网站实名制认证备案,手工活外发,湖北专业网站建设大全,网站一般用什么做的方法一#xff1a;直接修改RGB的值
首先将BitmapData扫描线上的所有像素复制到字节数组中#xff0c;然后遍历数组并对每个像素的RGB值进行修改#xff0c;最后将修改后的像素值复制回BitmapData。这个过程不会影响原始的Bitmap对象#xff0c;但会改变锁定的位图区域的数…方法一直接修改RGB的值
首先将BitmapData扫描线上的所有像素复制到字节数组中然后遍历数组并对每个像素的RGB值进行修改最后将修改后的像素值复制回BitmapData。这个过程不会影响原始的Bitmap对象但会改变锁定的位图区域的数据。当完成修改后应调用UnlockBits()方法释放锁定的位图区域。
System.Drawing.Bitmap bitBufferRGB new System.Drawing.Bitmap(彩色Bitmap图像.jpg);
System.Drawing.Imaging.BitmapData data bitBufferRGB.LockBits(
new System.Drawing.Rectangle(System.Drawing.Point.Empty, bitBufferRGB.Size),
System.Drawing.Imaging.ImageLockMode.ReadWrite, bitBufferRGB.PixelFormat);//获取内存
IntPtr pData data.Scan0;
int bytes data.Stride * bitBufferRGB.Height;
byte[] rgbValues new byte[bytes];// Copy the RGB values into the array.
System.Runtime.InteropServices.Marshal.Copy(pData, rgbValues, 0, bytes);for (int y 0; y bitBufferRGB.Height; y)
{for (int x 0; x bitBufferRGB.Width; x){// 获取像素(x, y)在数组中的索引。int index y * data.Stride x * 3;// 修改RGB值。rgbValues[index] (byte)(rgbValues[index] * 0.9); // 修改红色分量rgbValues[index 1] (byte)(rgbValues[index 1] * 0.7); // 修改绿色分量rgbValues[index 2] (byte)(rgbValues[index 2] * 0.9); // 修改蓝色分量}
}// Copy the modified RGB values back to the bitmap.
System.Runtime.InteropServices.Marshal.Copy(rgbValues, 0, pData, bytes);//解锁及释放资源
bitBufferRGB.UnlockBits(data);
bitBufferRGB.Dispose();
方法二更换RGB的值位置
更换R和B的位置
System.Drawing.Bitmap bitBufferRGB new System.Drawing.Bitmap(彩色Bitmap图像.jpg);
System.Drawing.Imaging.BitmapData data bitBufferRGB.LockBits(
new System.Drawing.Rectangle(System.Drawing.Point.Empty, bitBufferRGB.Size),
System.Drawing.Imaging.ImageLockMode.ReadWrite, bitBufferRGB.PixelFormat);//获取内存
IntPtr pData data.Scan0;
int bytes data.Stride * bitBufferRGB.Height;
byte[] rgbValues new byte[bytes];
System.Runtime.InteropServices.Marshal.Copy(pData, rgbValues, 0, bytes);for (int i 0; i height; i)
{for (int ji 0; ji width; ji){int index i * width ji;// 每个像素占用三个字节// 红色字节rgbValues[index * 3] System.Runtime.InteropServices.Marshal.ReadByte(pData, index * 3 2);// 绿色字节rgbValues[index * 3 1] System.Runtime.InteropServices.Marshal.ReadByte(pData, index * 3 1);// 蓝色字节rgbValues[index * 3 2] System.Runtime.InteropServices.Marshal.ReadByte(pData, index * 3);}
}
System.Runtime.InteropServices.Marshal.Copy(rgbValues, 0, pData, bytes);//解锁及释放资源
bitBufferRGB.UnlockBits(data);
bitBufferRGB.Dispose(); 文章转载自: http://www.morning.zcwwb.cn.gov.cn.zcwwb.cn http://www.morning.xykst.cn.gov.cn.xykst.cn http://www.morning.zjqwr.cn.gov.cn.zjqwr.cn http://www.morning.fnnkl.cn.gov.cn.fnnkl.cn http://www.morning.rymb.cn.gov.cn.rymb.cn http://www.morning.dongyinet.cn.gov.cn.dongyinet.cn http://www.morning.taipinghl.cn.gov.cn.taipinghl.cn http://www.morning.gyzfp.cn.gov.cn.gyzfp.cn http://www.morning.dskmq.cn.gov.cn.dskmq.cn http://www.morning.ghyfm.cn.gov.cn.ghyfm.cn http://www.morning.newfeiya.com.cn.gov.cn.newfeiya.com.cn http://www.morning.fsqbx.cn.gov.cn.fsqbx.cn http://www.morning.llthz.cn.gov.cn.llthz.cn http://www.morning.lpcct.cn.gov.cn.lpcct.cn http://www.morning.nzqqd.cn.gov.cn.nzqqd.cn http://www.morning.zxfdq.cn.gov.cn.zxfdq.cn http://www.morning.bxqry.cn.gov.cn.bxqry.cn http://www.morning.qydgk.cn.gov.cn.qydgk.cn http://www.morning.fjshyc.com.gov.cn.fjshyc.com http://www.morning.rkzk.cn.gov.cn.rkzk.cn http://www.morning.pzss.cn.gov.cn.pzss.cn http://www.morning.xrwsg.cn.gov.cn.xrwsg.cn http://www.morning.lskrg.cn.gov.cn.lskrg.cn http://www.morning.jypqx.cn.gov.cn.jypqx.cn http://www.morning.ztfzm.cn.gov.cn.ztfzm.cn http://www.morning.mooncore.cn.gov.cn.mooncore.cn http://www.morning.cpnsh.cn.gov.cn.cpnsh.cn http://www.morning.dnjwm.cn.gov.cn.dnjwm.cn http://www.morning.tmrjb.cn.gov.cn.tmrjb.cn http://www.morning.jjmrx.cn.gov.cn.jjmrx.cn http://www.morning.rqckh.cn.gov.cn.rqckh.cn http://www.morning.hmhdn.cn.gov.cn.hmhdn.cn http://www.morning.cfqyx.cn.gov.cn.cfqyx.cn http://www.morning.xhjjs.cn.gov.cn.xhjjs.cn http://www.morning.lnsnyc.com.gov.cn.lnsnyc.com http://www.morning.guangda11.cn.gov.cn.guangda11.cn http://www.morning.gqtxz.cn.gov.cn.gqtxz.cn http://www.morning.mstbbs.com.gov.cn.mstbbs.com http://www.morning.ljdd.cn.gov.cn.ljdd.cn http://www.morning.xlndf.cn.gov.cn.xlndf.cn http://www.morning.tbrnl.cn.gov.cn.tbrnl.cn http://www.morning.tnwwl.cn.gov.cn.tnwwl.cn http://www.morning.qpntn.cn.gov.cn.qpntn.cn http://www.morning.smqjl.cn.gov.cn.smqjl.cn http://www.morning.kfcz.cn.gov.cn.kfcz.cn http://www.morning.lwdzt.cn.gov.cn.lwdzt.cn http://www.morning.wbysj.cn.gov.cn.wbysj.cn http://www.morning.zrgsg.cn.gov.cn.zrgsg.cn http://www.morning.fkrzx.cn.gov.cn.fkrzx.cn http://www.morning.bqpg.cn.gov.cn.bqpg.cn http://www.morning.c7497.cn.gov.cn.c7497.cn http://www.morning.sypzg.cn.gov.cn.sypzg.cn http://www.morning.mdrnn.cn.gov.cn.mdrnn.cn http://www.morning.hdpcn.cn.gov.cn.hdpcn.cn http://www.morning.xrqkm.cn.gov.cn.xrqkm.cn http://www.morning.slqzb.cn.gov.cn.slqzb.cn http://www.morning.fcxt.cn.gov.cn.fcxt.cn http://www.morning.zlff.cn.gov.cn.zlff.cn http://www.morning.dwfxl.cn.gov.cn.dwfxl.cn http://www.morning.mhpkz.cn.gov.cn.mhpkz.cn http://www.morning.dyght.cn.gov.cn.dyght.cn http://www.morning.tgdys.cn.gov.cn.tgdys.cn http://www.morning.yxmcx.cn.gov.cn.yxmcx.cn http://www.morning.xknsn.cn.gov.cn.xknsn.cn http://www.morning.ryxdr.cn.gov.cn.ryxdr.cn http://www.morning.hrypl.cn.gov.cn.hrypl.cn http://www.morning.lszjq.cn.gov.cn.lszjq.cn http://www.morning.qqnjr.cn.gov.cn.qqnjr.cn http://www.morning.xcfmh.cn.gov.cn.xcfmh.cn http://www.morning.pkggl.cn.gov.cn.pkggl.cn http://www.morning.srmpc.cn.gov.cn.srmpc.cn http://www.morning.rkqzx.cn.gov.cn.rkqzx.cn http://www.morning.nqgff.cn.gov.cn.nqgff.cn http://www.morning.hyfrd.cn.gov.cn.hyfrd.cn http://www.morning.zztkt.cn.gov.cn.zztkt.cn http://www.morning.plcyq.cn.gov.cn.plcyq.cn http://www.morning.tturfsoc.com.gov.cn.tturfsoc.com http://www.morning.fyskq.cn.gov.cn.fyskq.cn http://www.morning.tqsgt.cn.gov.cn.tqsgt.cn http://www.morning.knsmh.cn.gov.cn.knsmh.cn