欢迎来到天天文库
浏览记录
ID:1821999
大小:32.50 KB
页数:2页
时间:2017-11-13
《图片拉伸渐变问题》由会员上传分享,免费在线阅读,更多相关内容在学术论文-天天文库。
1、C#将一个很小的图片绘制到一个很大的区域(图片拉伸),会造成图片产生渐变的效果:如果设置:e.Graphics.InterpolationMode=System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;//采取相邻颜色填补的方式拉伸图片则会造成下面的效果:在拉伸区域的后面出现空白。解决这个问题有以下2种方法(方法2和方法3):intnSpanWidth=596;privatevoidForm1_Paint(objectsender,PaintEventArgse){if(myImage==null
2、)return;e.Graphics.DrawRectangle(Pens.Black,newRectangle(20,50,nSpanWidth,40));#region方法1:达不到要求e.Graphics.DrawImage(myImage,newRectangle(20,50,nSpanWidth,40));#endregion#region方法2System.Drawing.Imaging.ImageAttributesImgAtt=newSystem.Drawing.Imaging.ImageAttributes();ImgAtt.SetWrapM
3、ode(System.Drawing.Drawing2D.WrapMode.TileFlipXY);e.Graphics.DrawImage(myImage,newRectangle(20,100,nSpanWidth,40),0,0,myImage.Width,myImage.Height,GraphicsUnit.Pixel,ImgAtt);#endregion#region方法3TextureBrushTxbrus=newTextureBrush(myImage);Txbrus.WrapMode=System.Drawing.Drawing2D.Wrap
4、Mode.Tile;e.Graphics.FillRectangle(Txbrus,newRectangle(20,150,nSpanWidth,40));#endregion}ImagemyImage;privatevoidbutton1_Click(objectsender,EventArgse){OpenFileDialogopen=newOpenFileDialog();if(open.ShowDialog()==DialogResult.OK){myImage=Image.FromFile(open.FileName);}}
此文档下载收益归作者所有