471,319 Members | 1,831 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,319 software developers and data experts.

Transparent images

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.lem walk.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.

Nov 29 '05 #1
3 14676
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

James wrote:
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.lem walk.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.

Nov 30 '05 #2
You can use Bitmap.MakeTransparent to set a specific colour transparent.
--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

"James" <c_********@yahoo.co.uk> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
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.lem walk.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.

Nov 30 '05 #3
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

Dec 1 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Fearless Freep | last post: by
5 posts views Thread by Jim | last post: by
3 posts views Thread by Christopher Kurtis Koeber | last post: by
2 posts views Thread by lord.zoltar | last post: by
9 posts views Thread by Chuck Anderson | last post: by
11 posts views Thread by Marge | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.