我如何使用图形绘制创建一个256x256的色彩空间图像?目前我正在使用指针循环遍历每个像素位置并对其进行设置。蓝色从X轴的0到255,绿色从Y轴的0到255.如下所示初始化图像。
Bitmap image = new Bitmap(256, 256);
imageData = image.LockBits(new Rectangle(0, 0, 256, 256),
ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
for (int row = 0; row < 256; row++)
{
byte* ptr = (byte*)imageData.Scan0 + (row * 768);
for (int col = 0; col < 256; col++)
{
ptr[col * 3] = (byte)col;
ptr[col * 3 + 1] = (byte)(255 - row);
ptr[col * 3 + 2] = 0;
}
}
我有一个滑块,它在红色上的取值范围是0...255。每次拖动滑块,它都会进入下面的循环并更新图片。
for (int row = 0; row < 256; row++)
{
byte* ptr = (byte*)imageData.Scan0 + (row * 768);
for (int col = 0; col < 256; col++)
{
ptr[col * 3 + 2] = (byte)trackBar1.Value;
}
}
我已经找到了使用ColorMatrix来滚动部分的方法,但是如何在不使用指针或SetPixel的情况下初始化图像呢?