图片处理工具(C#)
今天给大家介绍一个小图片处理工具,或许对有些人有帮助。
原文地址:
http://www.codeproject.com/articles/33838/image-processing-using-c
先上张图吸引一下眼光,
接下来大概讲讲都有什么功能。
1、颜色滤镜
颜色滤镜实现过程简单,我们来看看源码:
public void SetColorFilter(ColorFilterTypes colorFilterType) { Bitmap temp = (Bitmap)_currentBitmap; Bitmap bmap = (Bitmap)temp.Clone(); Color c; for (int i = 0; i < bmap.Width; i++) { for (int j = 0; j < bmap.Height; j++) { c = bmap.GetPixel(i, j); int nPixelR = 0; int nPixelG = 0; int nPixelB = 0; if (colorFilterType == ColorFilterTypes.Red) { nPixelR = c.R; nPixelG = c.G - 255; nPixelB = c.B - 255; } else if (colorFilterType == ColorFilterTypes.Green) { nPixelR = c.R - 255; nPixelG = c.G; nPixelB = c.B - 255; } else if (colorFilterType == ColorFilterTypes.Blue) { nPixelR = c.R - 255; nPixelG = c.G - 255; nPixelB = c.B; } nPixelR = Math.Max(nPixelR, 0); nPixelR = Math.Min(255, nPixelR); nPixelG = Math.Max(nPixelG, 0); nPixelG = Math.Min(255, nPixelG); nPixelB = Math.Max(nPixelB, 0); nPixelB = Math.Min(255, nPixelB); bmap.SetPixel(i, j, Color.FromArgb((byte)nPixelR, (byte)nPixelG, (byte)nPixelB)); } } _currentBitmap = (Bitmap)bmap.Clone(); }
有三种过滤方式--红、绿、蓝,以红色为例:获取位图中每一个像素点的颜色值,然后获取红色成分值,其它两种颜色成分各减255。
所有的操作代码都在ImageHandler.cs文件中,大家还是自己看吧,我还是不讲代码了,对图像处理不懂丫。
2、缩放功能
3、Undo
哎呀,竟然还有undo功能,不过做的太鸡肋,其实就是声明两实例,保存起来进行恢复而已。
private Bitmap _currentBitmap; private Bitmap _bitmapbeforeProcessing; public void ResetBitmap() { if (_currentBitmap != null && _bitmapbeforeProcessing != null) { Bitmap temp = (Bitmap)_currentBitmap.Clone(); _currentBitmap = (Bitmap)_bitmapbeforeProcessing.Clone(); _bitmapbeforeProcessing = (Bitmap)temp.Clone(); } }
4、调整大小
大家都知道,调整小点没问题,调整大,那就是一浆糊。
5、翻转
6、插入文字、图片
还可以插入文字或者图片呢。
还有不少功能,我就不晒了,又不是我开发的。
原文地址:
http://www.codeproject.com/articles/33838/image-processing-using-c
原文上面有源码下载。
补充:
作者这里还有个WPF版本的:
http://www.codeproject.com/Articles/237226/Image-Processing-is-done-using-WPF
但是原文提供的源码没有添加项目引用,编译无法通过,我已经把引用的项目添加上,并且上传了,下载地址如下:
files.cnblogs.com/zhangzhi19861216/ImageProcessingWPF4.rar
分类: C#