簡體   English   中英

使用Alpha通道繪制位圖

[英]Draw Bitmap with alpha channel

我有一個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);
}

現在我想在Paint事件中復制bitmap 我這樣做是這樣的:

void Form1Paint(object sender, PaintEventArgs e)
{
    e.Graphics.DrawImageUnscaled(bitmap, 0, 0);
}

但是, DrawImageUnscaled復制像素並應用Alpha通道,因此Alpha == 0的像素將沒有任何效果。 但是我需要原始字節復制,因此還復制了alpha == 0的像素。 因此,這些操作的結果應該是e.Graphics包含bitmap精確字節副本。 怎么做?

摘要:繪制位圖時,我不想應用alpha通道,我只想復制像素。

在繪制圖像之前,將Graphics.CompositingMode設置為CompositingMode.SourceCopy

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM