Transparent images

  • Thread starter Thread starter James
  • Start date Start date
J

James

Hello,

I use to use borland c++ where I would create an image (with a black
background), and a mask (with a white background, where the image is
black). I would then And the mask and or the image. This created a
transparent copy.

I cannot find anyway to do this using c# - can anyone please help?

Current code to get the image up there:
Bitmap drawpad = new Bitmap(300, 300);
Graphics screen = CreateGraphics();
Graphics drawpadg = Graphics.FromImage(drawpad);
Bitmap lemframes =
(Bitmap)Bitmap.FromStream(this.GetType().Assembly.GetManifestResourceStream("WindowsApplication1.lemwalk.gif"));
drawpadg.Clear(this.BackColor);
drawpadg.DrawImage(lemframes, new Rectangle(x+lo[f], y,
lw[f], 46), lx[f], 0, lw[f], 46, GraphicsUnit.Pixel);

screen.DrawImage(drawpad, 0, 0);
screen.Dispose();
drawpadg.Dispose();
lemframes.Dispose();

Many thanks for reading this, James.
 
Although this does not work with a mask, rather a specific color, it
might be useful for you.

Check out the MakeTransparent() method of the Bitmap class. If turns
parts of the image transparent. You probably want the overload of the
method which takes one Color structure as parameter.

-Lenard
 
Thank you both - that worked perfectly.
One point for others who may read this - on a palette based image (ie
gif) if the transparent colour is black and you use a different black
pen, it'll make all black areas transparent! You need your transparent
colour to be unique.

James
 
Back
Top