473,466 Members | 1,326 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 14745
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Fearless Freep | last post by:
I know there's a PIL mailing list but I thought I would try the question here as well. I'm using PIL on Python 1.5.2 (stop laughing, it's what the ISP has for CGI and I don't have a choice) ...
5
by: Jim | last post by:
Now this is just weird. And yes, I validated the html and the stylesheet. I created a transparent gif image in Paint Shop Pro 7. I made the mistake of making a transparent png and went along...
8
by: djmanmaster | last post by:
Am I right in thinking that images with transparent areas (GIFs or PNGs) should allow clicks to "pass through" to any underlying elements behind them? I have had no luck getting this to work in...
2
by: Allan | last post by:
I've been trying to get this to work for days. I have a form which needs to be transparent (only the form background). On the form there are two images (32 bit PNGs) with alpha channel...
3
by: Christopher Kurtis Koeber | last post by:
Dear All, I know that I am asking a lot about images lately, but it is just that new issues keep arising. My issue now has to do with transparent images. When I display transparent images,...
0
by: MLH | last post by:
My question is not how to paste images in Access with transparent backgrounds. I've researched 4-6 year old postings adequately describing how to achieve this. Lebans' site does a good job of...
2
by: lord.zoltar | last post by:
I have a couple of images I'm using to try and pretty up some forms. They are PNG images with transparent parts. I have one of them partly overlaying the other, but my problem is with the...
9
by: Chuck Anderson | last post by:
Is it possible to overlay a transparent watermark on an image - dynamically? I'd like the result to look like this example: <http://www.cycletourist.com/temp/photo.php> That is a bit of...
11
by: Marge | last post by:
After importing a VB6 project into Express 2008 I have two gif's with transparency do not display correctly. In VB6 these pictures where used with the image object which had different properties...
2
by: neovantage | last post by:
Hey all, I have created transparent PNG images from text dynamically. But it edges are pixel-ate or we can say edges are distorted. Here is my LINK which shows my generated transparent PNG image....
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.