473,699 Members | 2,278 Online
Bytes | Software Development & Data Engineering Community
+ 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.FromIm age(drawpad);
Bitmap lemframes =
(Bitmap)Bitmap. FromStream(this .GetType().Asse mbly.GetManifes tResourceStream ("WindowsApplic ation1.lemwalk. gif"));
drawpadg.Clear( this.BackColor) ;
drawpadg.DrawIm age(lemframes, new Rectangle(x+lo[f], y,
lw[f], 46), lx[f], 0, lw[f], 46, GraphicsUnit.Pi xel);

screen.DrawImag e(drawpad, 0, 0);
screen.Dispose( );
drawpadg.Dispos e();
lemframes.Dispo se();

Many thanks for reading this, James.

Nov 29 '05 #1
3 14755
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.FromIm age(drawpad);
Bitmap lemframes =
(Bitmap)Bitmap. FromStream(this .GetType().Asse mbly.GetManifes tResourceStream ("WindowsApplic ation1.lemwalk. gif"));
drawpadg.Clear( this.BackColor) ;
drawpadg.DrawIm age(lemframes, new Rectangle(x+lo[f], y,
lw[f], 46), lx[f], 0, lw[f], 46, GraphicsUnit.Pi xel);

screen.DrawImag e(drawpad, 0, 0);
screen.Dispose( );
drawpadg.Dispos e();
lemframes.Dispo se();

Many thanks for reading this, James.

Nov 30 '05 #2
You can use Bitmap.MakeTran sparent 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_********@yah oo.co.uk> wrote in message
news:11******** **************@ g49g2000cwa.goo glegroups.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.FromIm age(drawpad);
Bitmap lemframes =
(Bitmap)Bitmap. FromStream(this .GetType().Asse mbly.GetManifes tResourceStream ("WindowsApplic ation1.lemwalk. gif"));
drawpadg.Clear( this.BackColor) ;
drawpadg.DrawIm age(lemframes, new Rectangle(x+lo[f], y,
lw[f], 46), lx[f], 0, lw[f], 46, GraphicsUnit.Pi xel);

screen.DrawImag e(drawpad, 0, 0);
screen.Dispose( );
drawpadg.Dispos e();
lemframes.Dispo se();

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
13758
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) Anyway. I have a basic image and I need to overlay an image on top of it and let some of the basic image show through. Just as an aside the images are not of the same size and the top image needs to be pasted
5
7529
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 merrily until I viewed the pages (it's a multi-page three and two column site with an underlying stylesheet) in IE6. The transparent png worked fine in Mozilla but broke IE6. Sooooo, I recreate the image as a gif and it seems to work just fine in both...
8
6488
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 IE or Firefox. I have tried GIF and PNG with 'binary' transparency and PNG24 with 'alpha' transparency (obviously the latter won't work in IE without the AlphaImageLoader trick). Here is a test page for you to see it not working in action:
2
8573
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 information, in one case the alpha information is used to display a shadow, and the other has a shadow and a few other things. One of these images will change on a random basis (every five minutes or so) and the other is the background for display data. ...
3
1883
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, sometimes either the previous image displayed is now in the transparent area or sometimes even the buffer that is on the screen. I tried to refresh the control but still no luck. Any suggestions? Thank you in advance! Sincerely, Christopher Koeber
0
7015
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 pointing out the peculiarities (http://www.lebans.com/transparent.htm) What I'm having difficulty with is an image I've pasted in a report with a transparent background, showing up as such when viewed onscreen with report preview but whose...
2
2356
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 transparent parts: If Image1 is over Image2, I cannot see Image2. The transparent parts of the images are coloured with the background colour of the form, so it seems that the transparency is somewhat respected - how do I get the transparent part to show...
9
5866
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 overkill, but you can see what I mean. The watermark image (a png image) is included separately below the photo. I tried using a class from phpclasses.org <http://www.phpclasses.org/browse/package/1580.html...
11
4423
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 to the picturebox unfortunately there only seems to be the picturebox option in the toolbox of Express 2008? any ideas/help PLEASE :o)
2
3477
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. Can someone help me out to sort out my problem i will be very grateful to him as i am stuck bad with this issue and i am not figuring out how to fix this. Here is my Code which generate transparent PNG images <img...
0
8691
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9180
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9038
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8920
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8887
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7755
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4378
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4633
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3060
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 we have to send another system

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.