M
MS
Hi all,
I create a 800*500 offscreen bitmap and want to make it to transpaency.
But it failed.
Here is my testing code.
----------------------------------------------------------------------------
-----------------------------------------------
private Bitmap offBitmap = null;
private ImageAttributes imgAtt = new ImageAttributes();
private void Form1_Paint(object sender,
System.Windows.Forms.PaintEventArgs e)
{
Graphics g;
Rectangle rt = new Rectangle(0, 0, 800, 500);
if (this.offBitmap == null)
{
this.offBitmap = new Bitmap(800, 500);
}
g= Graphics.FromImage(this.offBitmap);
g.Clear(Color.FromArgb(255, 0, 255));
Pen pen = new Pen(Color.Pink);
g.DrawLine(pen, 0, 0, 800, 500);
pen.Dispose();
g.Dispose();
imgAtt.SetColorKey(Color.FromArgb(255, 0, 255),
Color.FromArgb(255,0,255));
e.Graphics.DrawImage(this.offBitmap, rt, 0, 0, 800, 500,
GraphicsUnit.Pixel, this.imgAtt);
imgAtt.ClearColorKey();
}
Thanks in advance.
Luyun
I create a 800*500 offscreen bitmap and want to make it to transpaency.
But it failed.
Here is my testing code.
----------------------------------------------------------------------------
-----------------------------------------------
private Bitmap offBitmap = null;
private ImageAttributes imgAtt = new ImageAttributes();
private void Form1_Paint(object sender,
System.Windows.Forms.PaintEventArgs e)
{
Graphics g;
Rectangle rt = new Rectangle(0, 0, 800, 500);
if (this.offBitmap == null)
{
this.offBitmap = new Bitmap(800, 500);
}
g= Graphics.FromImage(this.offBitmap);
g.Clear(Color.FromArgb(255, 0, 255));
Pen pen = new Pen(Color.Pink);
g.DrawLine(pen, 0, 0, 800, 500);
pen.Dispose();
g.Dispose();
imgAtt.SetColorKey(Color.FromArgb(255, 0, 255),
Color.FromArgb(255,0,255));
e.Graphics.DrawImage(this.offBitmap, rt, 0, 0, 800, 500,
GraphicsUnit.Pixel, this.imgAtt);
imgAtt.ClearColorKey();
}
Thanks in advance.
Luyun