图片处理工具(C#)
圖片處理工具(C#)
今天給大家介紹一個(gè)小圖片處理工具,或許對(duì)有些人有幫助。
原文地址:
http://www.codeproject.com/articles/33838/image-processing-using-c
先上張圖吸引一下眼光,
接下來大概講講都有什么功能。
1、顏色濾鏡
顏色濾鏡實(shí)現(xiàn)過程簡單,我們來看看源碼:
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();
}
有三種過濾方式--紅、綠、藍(lán),以紅色為例:獲取位圖中每一個(gè)像素點(diǎn)的顏色值,然后獲取紅色成分值,其它兩種顏色成分各減255。
所有的操作代碼都在ImageHandler.cs文件中,大家還是自己看吧,我還是不講代碼了,對(duì)圖像處理不懂丫。
2、縮放功能
3、Undo
哎呀,竟然還有undo功能,不過做的太雞肋,其實(shí)就是聲明兩實(shí)例,保存起來進(jìn)行恢復(fù)而已。
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、調(diào)整大小
大家都知道,調(diào)整小點(diǎn)沒問題,調(diào)整大,那就是一漿糊。
5、翻轉(zhuǎn)
6、插入文字、圖片
還可以插入文字或者圖片呢。
還有不少功能,我就不曬了,又不是我開發(fā)的。
原文地址:
http://www.codeproject.com/articles/33838/image-processing-using-c
原文上面有源碼下載。
補(bǔ)充:
作者這里還有個(gè)WPF版本的:
http://www.codeproject.com/Articles/237226/Image-Processing-is-done-using-WPF
但是原文提供的源碼沒有添加項(xiàng)目引用,編譯無法通過,我已經(jīng)把引用的項(xiàng)目添加上,并且上傳了,下載地址如下:
files.cnblogs.com/zhangzhi19861216/ImageProcessingWPF4.rar
分類:C#
作者:Leo_wl
出處:http://www.cnblogs.com/Leo_wl/
本文版權(quán)歸作者和博客園共有,歡迎轉(zhuǎn)載,但未經(jīng)作者同意必須保留此段聲明,且在文章頁面明顯位置給出原文連接,否則保留追究法律責(zé)任的權(quán)利。
版權(quán)信息
總結(jié)
以上是生活随笔為你收集整理的图片处理工具(C#)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: lol愚人节皮肤是限定么(英雄联盟无限火
- 下一篇: WampServer更改或重置数据库密码