资源简介
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个文件信息
评论
共有 条评论