在C#通过中通过BitmapData可以得到图像的基本数据,进而进行相关的图像处理工作。
也可以通过向BitmapData添充数据,进用数据去生成一幅图像。
itmap bitmap = new Bitmap(pictureBox1.Image);
int width = bitmap.Width;
int height = bitmap.Height;
System.Drawing.Imaging.BitmapData bitmapData = bitmap.LockBits(new Rectangle(0, 0, width, height), System.Drawing.Imaging.ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
unsafe
{
for (int i = 0; i < bitmap.Height; i++)
{
for (int j = 0; j < bitmap.Width*3; j+=3)
{
((byte*)bitmapData.Scan0)[i*bitmap.Width*3+j+2] = 0;
}
}
}
Bitmap bitmap2 = new Bitmap(bitmap.Width, bitmap.Height, bitmap.Width * 3, System.Drawing.Imaging.PixelFormat.Format24bppRgb, bitmapData.Scan0);
pictureBox2.Image = bitmap2;
C#之BitmapData应用1
最新推荐文章于 2021-11-16 11:02:05 发布
本文介绍如何在C#中利用BitmapData类获取图像数据,并对其进行处理。具体包括锁定位图数据以便读写,修改图像像素颜色,以及根据处理后的数据重新生成新的位图。
1万+

被折叠的 条评论
为什么被折叠?



