版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026河南郑州管城区紫东路社区卫生服务中心招聘3人备考题库带答案详解(完整版)
- 2026浙江工业大学地理信息学院招聘科研助理1人备考题库(人才派遣B2岗)(含答案详解)
- 2026江苏徐州市新盛集团下属中山置业公司招聘1人备考题库及答案详解(历年真题)
- 2026浙江金华市武义县消防救援大队招聘备考题库带答案详解(完整版)
- 2026江苏常铝铝业集团股份有限公司招聘4人备考题库及1套完整答案详解
- 2026宁夏银川市卫生健康委员会所属事业单位自主招聘博士研究生19人备考题库含答案详解(考试直接用)
- 2026黑龙江牡丹江市穆棱市特聘农技员招募8人备考题库含答案详解(基础题)
- 2026内蒙古巴彦淖尔市临河区老年大学班主任储备人才招募备考题库及答案详解(真题汇编)
- 2026年新疆工业学院招聘事业单位工作人员备考题库(第一批61人)附答案详解(精练)
- 2026浙江嘉兴市秀洲区招聘社区工作者33人备考题库含答案详解
- 大学生《思想道德与法治》考试复习题及答案
- 河南省历年中考语文现代文阅读真题49篇(含答案)(2003-2023)
- DL∕T 5210.4-2018 电力建设施工质量验收规程 第4部分:热工仪表及控制装置
- 神经源性肠道功能障碍的康复护理
- 毕业设计-螺纹轴数控加工工艺设计
- 食品安全风险评估报告
- 差热分析法(DTA)课件
- 日本宪法完整版本
- 钢材理论重量表大全(经典)
- 肝硬化门脉高压症的介入治疗
- 全2021年内蒙古呼伦贝尔市、兴安盟中考数学试卷含答案
评论
0/150
提交评论