C#图像透明度调整的方法
程序员文章站
2022-05-15 14:23:05
本文实例讲述了c#图像透明度调整的方法。分享给大家供大家参考。具体如下:
//定义图像透明度调整函数
public bitmap ptransparentadj...
本文实例讲述了c#图像透明度调整的方法。分享给大家供大家参考。具体如下:
//定义图像透明度调整函数 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%):
希望本文所述对大家的c#程序设计有所帮助。
上一篇: Javascript/js 的浅拷贝与深拷贝(复制)学习随笔
下一篇: 第一周作业