我有一个Format32bppArgb
后备缓冲区,我画了几行:
var g = Graphics.FromImage(bitmap);
g.Clear(Color.FromArgb(0));
var rnd = new Random();
for (int i = 0; i < 5000; i++) {
int x1 = rnd.Next(ClientRectangle.Left, ClientRectangle.Right);
int y1 = rnd.Next(ClientRectangle.Top, ClientRectangle.Bottom);
int x2 = rnd.Next(ClientRectangle.Left, ClientRectangle.Right);
int y2 = rnd.Next(ClientRectangle.Top, ClientRectangle.Bottom);
Color color = Color.FromArgb(rnd.Next(0, 255), rnd.Next(0, 255), rnd.Next(0, 255));
g.DrawLine(new Pen(color), x1, y1, x2, y2);
}
现在我要在bitmap
事件中复制Paint
。我是这样做的:
void Form1Paint(object sender, PaintEventArgs e)
{
e.Graphics.DrawImageUnscaled(bitmap, 0, 0);
}
Hovewer,DrawImageUnscaled
复制像素并应用alpha通道,因此alpha == 0的像素不会产生任何影响。但我需要原始字节副本,因此也会复制alpha == 0的像素。因此,这些操作的结果应该是e.Graphics
包含bitmap
的精确字节副本。怎么做?
摘要:绘制位图时,我不想应用Alpha通道,我只想复制像素。