C#圖像透明度調(diào)整的方法
更新時(shí)間:2015年04月24日 11:36:59 作者:滄海一粟……
這篇文章主要介紹了C#圖像透明度調(diào)整的方法,涉及C#操作圖像透明度的相關(guān)技巧,需要的朋友可以參考下
本文實(shí)例講述了C#圖像透明度調(diào)整的方法。分享給大家供大家參考。具體如下:
//定義圖像透明度調(diào)整函數(shù) public Bitmap PTransparentAdjust(Bitmap src,int num) { try { int w = src.Width; int h = src.Height; Bitmap dstBitmap = new Bitmap(src.Width, src.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb); System.Drawing.Imaging.BitmapData srcData = src.LockBits(new Rectangle(0, 0, w, h), System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); System.Drawing.Imaging.BitmapData dstData = dstBitmap.LockBits(new Rectangle(0, 0, w, h), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); unsafe { byte* pIn = (byte*)srcData.Scan0.ToPointer(); byte* pOut = (byte*)dstData.Scan0.ToPointer(); byte* p; int stride = srcData.Stride; int r, g, b; for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { p = pIn; b = pIn[0]; g = pIn[1]; r = pIn[2]; pOut[1] = (byte)g; pOut[2] = (byte)r; pOut[3] = (byte)num; pOut[0] = (byte)b; pIn += 4; pOut += 4; } pIn += srcData.Stride - w * 4; pOut += srcData.Stride - w * 4; } src.UnlockBits(srcData); dstBitmap.UnlockBits(dstData); return dstBitmap; } } catch (Exception e) { MessageBox.Show(e.Message.ToString()); return null; } }
原圖:
效果圖(50%):
希望本文所述對(duì)大家的C#程序設(shè)計(jì)有所幫助。
相關(guān)文章
C#開(kāi)源的AOP框架--KingAOP基礎(chǔ)
這篇文章主要介紹了一款C#開(kāi)源的AOP框架--KingAOP框架的基礎(chǔ)知識(shí),對(duì)于想學(xué)習(xí)AOP的小伙伴來(lái)說(shuō),非常不錯(cuò),希望大家能夠喜歡。2015-12-12C#/.Net 中快速批量給SQLite數(shù)據(jù)庫(kù)插入測(cè)試數(shù)據(jù)
這篇文章主要介紹了C#/.Net 中快速批量給SQLite數(shù)據(jù)庫(kù)插入測(cè)試數(shù)據(jù),本文直接給出實(shí)例代碼,需要的朋友可以參考下2015-06-06C#動(dòng)態(tài)webservice調(diào)用接口
動(dòng)態(tài)調(diào)用webservice,就可以不用添加web引用了,上線的話也只是需要改一下wsdl地址就可以了2015-05-05C#實(shí)現(xiàn)簡(jiǎn)單的文件加密與解密方式
這篇文章主要介紹了C#實(shí)現(xiàn)簡(jiǎn)單的文件加密與解密方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-01-01將Qt項(xiàng)目升級(jí)到Qt6吐血經(jīng)驗(yàn)總結(jié)
很多朋友向小編反饋將Qt項(xiàng)目升級(jí)到Qt6頻繁出錯(cuò),該如何處理呢,今天小編給大家?guī)?lái)了將Qt項(xiàng)目升級(jí)到Qt6吐血經(jīng)驗(yàn)總結(jié),感興趣的朋友一起看看吧2021-07-07