C#中Bitmap类实现对图像操作的一些方法(转)
生活随笔
收集整理的這篇文章主要介紹了
C#中Bitmap类实现对图像操作的一些方法(转)
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
| | http://hi.baidu.com/donetsky/blog/item/e95ab635eb7af21090ef3984.html |
============================================ C#Bitmap代替另一個Bitmap的某部分
Bitmap bm = new Bitmap(寬度, 高度);// 新建一個 Bitmap 位圖
System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bm); // 根據(jù)新建的 Bitmap 位圖,創(chuàng)建畫布
g.Clear(System.Drawing.Color.Black);// 使用黑色重置畫布
g.DrawImage(源位圖, ......); // 繪制“源位圖”,后面有若干參數(shù)控制大小、坐標(biāo)等等功能。
==================================================
C# 圖片處理之:旋轉(zhuǎn)圖片任意角度
?????///?<summary>
?????????///?任意角度旋轉(zhuǎn)
?????????///?</summary>
?????????///?<param name="bmp">原始圖Bitmap</param>
?????????///?<param name="angle">旋轉(zhuǎn)角度</param>
?????????///?<param name="bkColor">背景色</param>
?????????///?<returns>輸出Bitmap</returns>
?????????public?static?Bitmap KiRotate(Bitmap bmp,?float?angle, Color bkColor)
?????????{
?????????????int?w?=?bmp.Width?+?2;
?????????????int?h?=?bmp.Height?+?2;
?
??????????????PixelFormat pf;
?
?????????????if?(bkColor?==?Color.Transparent)
?????????????{
??????????????????pf?=?PixelFormat.Format32bppArgb;
??????????????}
?????????????else
?????????????{
??????????????????pf?=?bmp.PixelFormat;
??????????????}
?
??????????????Bitmap tmp?=?new?Bitmap(w, h, pf);
??????????????Graphics g?=?Graphics.FromImage(tmp);
??????????????g.Clear(bkColor);
??????????????g.DrawImageUnscaled(bmp,?1,?1);
??????????????g.Dispose();
?
??????????????GraphicsPath path?=?new?GraphicsPath();
??????????????path.AddRectangle(new?RectangleF(0f, 0f, w, h));
??????????????Matrix mtrx?=?new?Matrix();
??????????????mtrx.Rotate(angle);
??????????????RectangleF rct?=?path.GetBounds(mtrx);
?
??????????????Bitmap dst?=?new?Bitmap((int)rct.Width, (int)rct.Height, pf);
??????????????g?=?Graphics.FromImage(dst);
??????????????g.Clear(bkColor);
??????????????g.TranslateTransform(-rct.X,?-rct.Y);
??????????????g.RotateTransform(angle);
??????????????g.InterpolationMode?=?InterpolationMode.HighQualityBilinear;
??????????????g.DrawImageUnscaled(tmp,?0,?0);
??????????????g.Dispose();
?
??????????????tmp.Dispose();
?
?????????????return?dst;
??????????}
總結(jié)
以上是生活随笔為你收集整理的C#中Bitmap类实现对图像操作的一些方法(转)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: AVS解码器在DSP平台上的优化
- 下一篇: 多媒体视频知识入门贴zt(二)