private void 灰度转换ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (curBitmap != null)
{
//位图矩形,0, 0, curBitmap.Width, curBitmap.Height分别表示左上角x,y坐标,矩形宽度,高度。
Rectangle rect = new Rectangle(0, 0, curBitmap.Width, curBitmap.Height);
//以可读写的方式锁定全部位图像素
System.Drawing.Imaging.BitmapData bmpData = curBitmap.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite, curBitmap.PixelFormat);
//得到首地址
IntPtr ptr = bmpData.Scan0;
//定义被锁定的数组大小,由位图数据与未用空间组成
int bytes = bmpData.Stride*bmpData.Height;
byte[] rgbValues = new byte[bytes];
System.Runtime.InteropServices.Marshal.Copy(ptr, rgbValues, 0, bytes);
//灰度化
double colorTemp = 0;
for(int i=0;i<bmpData.
24位bmp图像转成灰度图像
最新推荐文章于 2021-01-16 17:41:24 发布