資源簡介
c# 圖片放大縮小(鼠標點擊放大區域為原始大小)

代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.ComponentModel;
using?System.Data;
using?System.Drawing;
using?System.Linq;
using?System.Text;
using?System.Windows.Forms;
using?System.Drawing.Imaging;
namespace?WindowsFormsApplication1
{
????public?partial?class?Form1?:?Form
????{
????????private?Bitmap?m_Image;
????????private?Point?m_StarPoint?=?Point.Empty;
????????private?Point?m_ViewPoint?=?Point.Empty;
????????private?string?Img?=?“../../1.jpg“;
????????private?int?Img_Width?Img_Height;//寬?高
????????private?bool?_isLeftMouseDown?=?false;
????????public?Form1()
????????{
????????????InitializeComponent();
????????}
????????private?void?Form1_Load(object?sender?EventArgs?e)
????????{
????????????System.Drawing.Image?image?=?System.Drawing.Image.FromFile(@Img);?
????????????Img_Width?=?image.Width;//寬
????????????Img_Height?=?image.Height;//高
????????????m_Image?=?(Bitmap)Image.FromFile(@Img);
????????????this.pictureBox1.SizeMode?=?PictureBoxSizeMode.Zoom;
????????????pictureBox1.Image?=?m_Image.Clone(new?RectangleF(0?0?Img_Width?Img_Height)?PixelFormat.Format24bppRgb);
????????????this.pictureBox1.MouseDown?+=?this.pictureBox1_MouseDown;
????????}
????????public?float?StrToFloat(object?FloatString)//string轉float
????????{
????????????float?result;
????????????if?(FloatString?!=?null)
????????????{
????????????????if?(float.TryParse(FloatString.ToString()?out?result))
????????????????????return?result;
????????????????else
????????????????{
????????????????????return?(float)0.00;
????????????????}
????????????}
????????????else
????????????{
????????????????return?(float)0.00;
????????????}
????????}
????????private?void?pictureBox1_MouseDown(object?sender?MouseEventArgs?e)
????????{
????????????m_StarPoint?=?e.Location;
????????????decimal?C_pictureBox1Width?=?Math.Round((decimal)pictureBox1.Width?/?2?0);?//圖片框X中心點
????????????decimal?C_pictureBox1Height?=?Math.Round((decimal)pictureBox1.Height?/?2?0);?//圖片框Y中心點
????????????decimal?C_ImgWidth?=?Math.Round((decimal)Img_Width?/?2?0);?//圖片X中心點
????????????decimal?C_ImgHeight?=?Math.Round((decimal)Img_Height?/?2?0);?//圖片Y中心點
????????????decimal?C_WidthB?=?Math.Round((decimal)Img_Width?/?pictureBox1.Width?4);?//圖片與框X比
????????????decimal?C_HeightB?=?Math.Round((decimal)Img_Height?/?pictureBox1.Height?4);?//圖片與框Y比
????????????decimal?C_Width?=?Math.Round((decimal)C_WidthB?*?m_StarPoint.X?0);?//圖片鼠標獲取X點
????????????decimal?C_Height?=?Math.Round((decimal)C_HeightB?*?m_StarPoint.Y?0);?//圖片鼠標獲取Y點
????????????float?Tmp_Width?=?StrToFloat((C_Width?-?C_pictureBox1Width).ToString());
????????????float?Tmp_Height?=?StrToFloat((C_Height?-?C_pictureBox1Height).ToString());
????????????if?(Tmp_Width?1)?Tmp_Width?=?0;
????????????else?if?(Tmp_Width?>?(Img_Width?-?pictureBox1.Width))?Tmp_Width?=?Img_Width?-?pictureBox1.Width;
????????????if?(Tmp_Height?1)?Tmp_Height?=?0;
????????????else?if?(Tm
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件????????914??2012-11-22?16:46??圖片放大縮小.sln
????..A..H.?????24064??2012-11-22?20:35??圖片放大縮小.suo
?????文件?????260429??2012-09-13?14:28??WindowsFormsApplication1\1.jpg
?????文件??????12800??2012-11-22?20:34??WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.exe
?????文件??????28160??2012-11-22?20:34??WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.pdb
?????文件??????11600??2012-11-22?20:35??WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.vshost.exe
?????文件????????490??2010-03-17?22:39??WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.vshost.exe.manifest
?????文件???????4958??2012-11-22?20:34??WindowsFormsApplication1\Form1.cs
?????文件???????8558??2012-11-22?19:06??WindowsFormsApplication1\Form1.Designer.cs
?????文件???????5817??2012-11-22?19:06??WindowsFormsApplication1\Form1.resx
?????文件???????6484??2012-11-22?20:34??WindowsFormsApplication1\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache
?????文件????????316??2012-11-22?19:06??WindowsFormsApplication1\obj\x86\Debug\GenerateResource.read.1.tlog
?????文件????????798??2012-11-22?19:06??WindowsFormsApplication1\obj\x86\Debug\GenerateResource.write.1.tlog
?????文件???????1348??2012-11-22?20:35??WindowsFormsApplication1\obj\x86\Debug\WindowsFormsApplication1.csproj.FileListAbsolute.txt
?????文件??????12800??2012-11-22?20:34??WindowsFormsApplication1\obj\x86\Debug\WindowsFormsApplication1.exe
?????文件????????180??2012-11-22?19:06??WindowsFormsApplication1\obj\x86\Debug\WindowsFormsApplication1.Form1.resources
?????文件??????28160??2012-11-22?20:34??WindowsFormsApplication1\obj\x86\Debug\WindowsFormsApplication1.pdb
?????文件????????180??2012-11-22?16:46??WindowsFormsApplication1\obj\x86\Debug\WindowsFormsApplication1.Properties.Resources.resources
?????文件????????505??2012-11-22?16:46??WindowsFormsApplication1\Program.cs
?????文件???????1380??2012-11-22?16:46??WindowsFormsApplication1\Properties\AssemblyInfo.cs
?????文件???????2896??2012-11-22?16:46??WindowsFormsApplication1\Properties\Resources.Designer.cs
?????文件???????5612??2012-11-22?16:46??WindowsFormsApplication1\Properties\Resources.resx
?????文件???????1107??2012-11-22?16:46??WindowsFormsApplication1\Properties\Settings.Designer.cs
?????文件????????249??2012-11-22?16:46??WindowsFormsApplication1\Properties\Settings.settings
?????文件???????3707??2012-11-22?16:46??WindowsFormsApplication1\WindowsFormsApplication1.csproj
?????目錄??????????0??2012-11-22?16:46??WindowsFormsApplication1\obj\x86\Debug\TempPE
?????目錄??????????0??2012-11-22?20:34??WindowsFormsApplication1\obj\x86\Debug
?????目錄??????????0??2012-11-22?16:46??WindowsFormsApplication1\bin\Debug
?????目錄??????????0??2012-11-22?16:46??WindowsFormsApplication1\obj\x86
?????目錄??????????0??2012-11-22?16:46??WindowsFormsApplication1\bin
............此處省略6個文件信息
評論
共有 條評論