C#图片处理总结——叠加、缩放、鼠标拖动_第1页
C#图片处理总结——叠加、缩放、鼠标拖动_第2页
C#图片处理总结——叠加、缩放、鼠标拖动_第3页
C#图片处理总结——叠加、缩放、鼠标拖动_第4页
C#图片处理总结——叠加、缩放、鼠标拖动_第5页
已阅读5页,还剩2页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、C#图片处理总结一一叠加、缩放、鼠标拖动2011-05-0312:371265人阅读评论收藏举报c#floatimageobjectstringnull/用到的命名空间/usingSystem.Drawing;usingSystem.Drawing.Drawing2D;usingSystem.Drawing.lmaging;/两张图片叠加,floatfImage(01)透明度/privatevoidgetMixlmage(floatfImage,stringstrFrontImage,stringstrBackImage)this.m_image.Dispose();Bitmapbackgro

2、und=newBitmap(strBackImage);BitmapfrontImage=newBitmap(strFrontlmage);intiwidth=background.Width>frontImage.Width?background.Width:frontImage.Width;intiheight=background.Height>frontImage.Height?background.Height:frontImage.Height;BitmapmixImage2=newBitmap(iwidth,iheight);/this.mixImage.Width=

3、iwidth;/this.mixImage.Height=iheight;Graphicsg=Graphics.Fromlmage(mixlmage2);floatcolormatrix=newfloat1,0,0,0,0,代表了代表了G代表了newfloat0,1,0,0,0,/newfloat0,0,1,0,0,/newfloat0,0,0,flmage,0,代表了Anewfloat0,0,0,0,1;ColorMatrixcm=newColorMatrix(colormatrix);ImageAttributesimageAtt=newlmageAttributes();imageAtt

4、.SetColorMatrix(cm,ColorMatrixFIag.Default,ColorAdjustType.Bitmap);g.Drawlmage(background,newPoint(O,0);g.DrawImage(frontlmage,newRectangle(0,0,frontImage.Width,frontImage.Height),0,0,frontImage.Width,frontImage.Height,GraphicsUnit.Pixel,imageAtt);this.pictureBox1.Image=mixImage2;this.pictureBox1.Up

5、date();this.m_ChangeSize=mixImage2;/图片的缩放/publicForm1()InitializeComponent();/写在初始化时,提高运算速度/base.SetStyle(ControlStyles.OptimizedDoubleBuffer|ControlStyles.AllPaintingInWmPaint|ControlStyles.UserPaint,true);base.SetStyle(ControlStyles.ResizeRedraw|ControlStyles.Selectable,true);/放大/privatevoidbutton

6、PicSizeEnlarge_Click(objectsender,EventArgse)this.nPicSize+;if(this.nPicSize<1)this.nPicSize=1;MessageBox.Show(”无法再减弱”);if(this.nPicSize>6)MessageBox.Show(”无法再增强”);this.nPicSize=6;elsethis.picSizeColor();if(this.nReset=0)mmage=m_Reset;if(this.pictureBox1.lmage.Width>this.splitContainer1.Pan

7、el1.Width&&this.pictureBox1.lmage.Height>this.splitContainer1.Panel1.Height&&pictureBox1.Image.Height>=mmage.Height*4)MessageBox.Show(”已是最大");elsethis.nReset=this.nReset+1;Rectangleoldrct;Bitmapbmp=(Bitmap)this.pictureBox1.Image;oldrct=newRectangle(0,0,bmp.Width,bmp.Height

8、);this.pictureBox1.Image=bmp;Bitmaptmpbmp=null;tmpbmp=newBitmap(bmp.Width*2,bmp.Height*2);if(bmp.Width<mmage.Width)oldrct=newRectangle(0,0,m_image.Width,m_image.Height);Graphicsg=Graphics.Fromlmage(tmpbmp);Rectanglenewrct=newRectangle(0,0,tmpbmp.Width,tmpbmp.Height);g.DrawImage(m_image,newrct,old

9、rct,GraphicsUnit.Pixel);g.lnterpolationMode=System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;pictureBoxI.Image=tmpbmp;g.Dispose();pictureBox1.Update();elseGraphicsg=Graphics.Fromlmage(tmpbmp);Rectanglenewrct=newRectangle(0,0,tmpbmp.Width,tmpbmp.Height);g.DrawImage(bmp,newrct,oldrct,Grap

10、hicsUnit.Pixel);g.lnterpolationMode=System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;pictureBox1.Image=tmpbmp;g.Dispose();pictureBox1.Update();this.mmage=(Bitmap)this.pictureBox1.Image;/缩小/privatevoidbuttonPicSizeNarrow_Click(objectsender,EventArgse)this.nPicSize-;if(this.nPicSize<1)

11、this.nPicSize=1;MessageBox.Show(”无法再缩小”);if(this.nPicSize>6)MessageBox.Show(”无法再增大”);this.nPicSize=6;elsethis.picSizeColor();if(this.nReset=0)mmage=m_Reset;if(pictureBoxl.lmage.Width<=this.splitContainerl.Panell.Width&&pictureBoxI.Image.Height<=this.splitContainer1.Panel1.Height)Mes

12、sageBox.Show(”已经最小”);elsethis.nReset=this.nReset-1;Rectangleoldrct;Bitmapbmp=(Bitmap)this.pictureBox1.Image;oldrct=newRectangle(0,0,bmp.Width,bmp.Height);this.pictureBox1.Image=bmp;Bitmaptmpbmp=null;tmpbmp=newBitmap(bmp.Width/2,bmp.Height/2);Graphicsg=Graphics.Fromlmage(tmpbmp);Rectanglenewrct=newRe

13、ctangle(0,0,tmpbmp.Width,tmpbmp.Height);g.Drawlmage(bmp,newrct,oldrct,GraphicsUnit.Pixel);g.lnterpolationMode=system.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;pictureBox1.Image=tmpbmp;g.Dispose();pictureBox1.Update();this.mmage=(Bitmap)this.pictureBox1.Image;/鼠标拖动图片/定义图片位置,全局变量/PointM_p

14、ot_p=newPoint();原始位置intMnt_mx=0,Mnt_my=0;/下次能继续intMnt_maxX,Mnt_maxY;加快读取用privatevoidpictureBox1_MouseDown(objectsender,MouseEventArgse)Bitmaptmpbmp=(Bitmap)this.pictureBox1.Image;M_pot_p=e.Location;Mnt_maxX=pictureBox1.Width-tmpbmp.Width;Mnt_maxY=pictureBox1.Height-tmpbmp.Height;Cursor=Cursors.SizeA

15、II;privatevoidpictureBox1_MouseMove(objectsender,MouseEventArgse)if(e.Button=MouseButtons.Left)/当按左键的时候/算差值Bitmaptmpbmp=(Bitmap)this.pictureBox1.Image;Mnt_mx=Mnt_mx-M_pot_p.X+e.X;Mnt_my=Mnt_my-M_pot_p.Y+e.Y;/锁定范围Mnt_mx=Math.Min(0,Math.Max(Mnt_maxX,M_int_mx);Mnt_my=Math.Min(0,Math.Max(Mnt_maxY,Mnt_my);Graphicsg

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

最新文档

评论

0/150

提交评论