欢迎来到天天文库
浏览记录
ID:35273121
大小:40.50 KB
页数:7页
时间:2019-03-22
《c#代码各种图像处理方法》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、各种图像处理方法底片效果privatevoidbutton1_Click(objectsender,EventArgse){//以底片效果显示图像try{intHeight=this.pictureBox1.Image.Height;intWidth=this.pictureBox1.Image.Width;Bitmapnewbitmap=newBitmap(Width,Height);Bitmapoldbitmap=(Bitmap)this.pictureBox1.Image;Colorpixel;for(intx=1;x2、ght;y++){intr,g,b;pixel=oldbitmap.GetPixel(x,y);r=255-pixel.R;g=255-pixel.G;b=255-pixel.B;newbitmap.SetPixel(x,y,Color.FromArgb(r,g,b));}}this.pictureBox1.Image=newbitmap;}catch(Exceptionex){MessageBox.Show(ex.Message,"信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information);}}柔化效果privatevoidbu3、tton1_Click(objectsender,EventArgse){//以柔化效果显示图像try{intHeight=this.pictureBox1.Image.Height;intWidth=this.pictureBox1.Image.Width;Bitmapbitmap=newBitmap(Width,Height);BitmapMyBitmap=(Bitmap)this.pictureBox1.Image;Colorpixel;//高斯模板int[]Gauss={1,2,1,2,4,2,1,2,1};for(intx=1;x4、y=1;y255?255:r;r=r<0?0:r;g=g>255?255:g;g=g<0?0:g5、;b=b>255?255:b;b=b<0?0:b;bitmap.SetPixel(x-1,y-1,Color.FromArgb(r,g,b));}this.pictureBox1.Image=bitmap;}catch(Exceptionex){MessageBox.Show(ex.Message,"信息提示");}} 锐化效果privatevoidbutton1_Click(objectsender,EventArgse){//以锐化效果显示图像try{intHeight=this.pictureBox1.Image.Height;intWidth=this.pictureBo6、x1.Image.Width;BitmapnewBitmap=newBitmap(Width,Height);BitmapoldBitmap=(Bitmap)this.pictureBox1.Image;Colorpixel;//拉普拉斯模板int[]Laplacian={-1,-1,-1,-1,9,-1,-1,-1,-1};for(intx=1;x7、++){pixel=oldBitmap.GetPixel(x+row,y+col);r+=pixel.R*Laplacian[Index];g+=pixel.G*Laplacian[Index];b+=pixel.B*Laplacian[Index];Index++;}//处理颜色值溢出r=r>255?255:r;r=r<0?0:r;g=g>255?255:g;g=g<0?0:g;b=b>255?255:b;b=b<0?0:b;newBitmap.SetPixel(x-1,y-1
2、ght;y++){intr,g,b;pixel=oldbitmap.GetPixel(x,y);r=255-pixel.R;g=255-pixel.G;b=255-pixel.B;newbitmap.SetPixel(x,y,Color.FromArgb(r,g,b));}}this.pictureBox1.Image=newbitmap;}catch(Exceptionex){MessageBox.Show(ex.Message,"信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information);}}柔化效果privatevoidbu
3、tton1_Click(objectsender,EventArgse){//以柔化效果显示图像try{intHeight=this.pictureBox1.Image.Height;intWidth=this.pictureBox1.Image.Width;Bitmapbitmap=newBitmap(Width,Height);BitmapMyBitmap=(Bitmap)this.pictureBox1.Image;Colorpixel;//高斯模板int[]Gauss={1,2,1,2,4,2,1,2,1};for(intx=1;x4、y=1;y255?255:r;r=r<0?0:r;g=g>255?255:g;g=g<0?0:g5、;b=b>255?255:b;b=b<0?0:b;bitmap.SetPixel(x-1,y-1,Color.FromArgb(r,g,b));}this.pictureBox1.Image=bitmap;}catch(Exceptionex){MessageBox.Show(ex.Message,"信息提示");}} 锐化效果privatevoidbutton1_Click(objectsender,EventArgse){//以锐化效果显示图像try{intHeight=this.pictureBox1.Image.Height;intWidth=this.pictureBo6、x1.Image.Width;BitmapnewBitmap=newBitmap(Width,Height);BitmapoldBitmap=(Bitmap)this.pictureBox1.Image;Colorpixel;//拉普拉斯模板int[]Laplacian={-1,-1,-1,-1,9,-1,-1,-1,-1};for(intx=1;x7、++){pixel=oldBitmap.GetPixel(x+row,y+col);r+=pixel.R*Laplacian[Index];g+=pixel.G*Laplacian[Index];b+=pixel.B*Laplacian[Index];Index++;}//处理颜色值溢出r=r>255?255:r;r=r<0?0:r;g=g>255?255:g;g=g<0?0:g;b=b>255?255:b;b=b<0?0:b;newBitmap.SetPixel(x-1,y-1
4、y=1;y255?255:r;r=r<0?0:r;g=g>255?255:g;g=g<0?0:g
5、;b=b>255?255:b;b=b<0?0:b;bitmap.SetPixel(x-1,y-1,Color.FromArgb(r,g,b));}this.pictureBox1.Image=bitmap;}catch(Exceptionex){MessageBox.Show(ex.Message,"信息提示");}} 锐化效果privatevoidbutton1_Click(objectsender,EventArgse){//以锐化效果显示图像try{intHeight=this.pictureBox1.Image.Height;intWidth=this.pictureBo
6、x1.Image.Width;BitmapnewBitmap=newBitmap(Width,Height);BitmapoldBitmap=(Bitmap)this.pictureBox1.Image;Colorpixel;//拉普拉斯模板int[]Laplacian={-1,-1,-1,-1,9,-1,-1,-1,-1};for(intx=1;x7、++){pixel=oldBitmap.GetPixel(x+row,y+col);r+=pixel.R*Laplacian[Index];g+=pixel.G*Laplacian[Index];b+=pixel.B*Laplacian[Index];Index++;}//处理颜色值溢出r=r>255?255:r;r=r<0?0:r;g=g>255?255:g;g=g<0?0:g;b=b>255?255:b;b=b<0?0:b;newBitmap.SetPixel(x-1,y-1
7、++){pixel=oldBitmap.GetPixel(x+row,y+col);r+=pixel.R*Laplacian[Index];g+=pixel.G*Laplacian[Index];b+=pixel.B*Laplacian[Index];Index++;}//处理颜色值溢出r=r>255?255:r;r=r<0?0:r;g=g>255?255:g;g=g<0?0:g;b=b>255?255:b;b=b<0?0:b;newBitmap.SetPixel(x-1,y-1
此文档下载收益归作者所有