473,386 Members | 1,745 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Save image to .PNG with transparent background?

I'm using the code show below (in VB.Net 2003) to create an image. I
want to save this image to a .PNG file such that when I subsequently
display it as part of a web page, the background of the image will be
transparent.

This test/learning code simply draws a diagonal green line across a
square box. When I display the resulting file on a web page, I want
only the line itself to be visible but what is happening is that the
entire "box" is shown (in a light grey color) with the line drawn
across it.

Any suggestions as to how I can do this?

Thanks.

-----------------------------------------------------------
Dim myPen As Pen = New Pen(Color.Green, 9))
Dim bmp As Bitmap = New Bitmap(100, 100)
Dim g As Graphics = Graphics.FromImage(bmp)

g.Clear(Color.Plum)
g.DrawLine(myPen, 0, 0, 100, 100)
bmp.MakeTransparent(Color.Plum)
bmp.Save("TestFile.png", System.Drawing.Imaging.ImageFormat.Png)
Nov 21 '05 #1
7 20129
Hi,

Try this instead.

Dim myPen As Pen = New Pen(Color.Green, 9)

Dim bmp As Bitmap = New Bitmap(100, 100)

Dim g As Graphics = Graphics.FromImage(bmp)

g.Clear(Color.Transparent)

g.DrawLine(myPen, 0, 0, 100, 100)

bmp.Save("TestFile.png", System.Drawing.Imaging.ImageFormat.Png)

Ken

------------------------

"Martin" <ma**********@comcast.net> wrote in message
news:i1********************************@4ax.com...
I'm using the code show below (in VB.Net 2003) to create an image. I
want to save this image to a .PNG file such that when I subsequently
display it as part of a web page, the background of the image will be
transparent.

This test/learning code simply draws a diagonal green line across a
square box. When I display the resulting file on a web page, I want
only the line itself to be visible but what is happening is that the
entire "box" is shown (in a light grey color) with the line drawn
across it.

Any suggestions as to how I can do this?

Thanks.

-----------------------------------------------------------
Dim myPen As Pen = New Pen(Color.Green, 9))
Dim bmp As Bitmap = New Bitmap(100, 100)
Dim g As Graphics = Graphics.FromImage(bmp)

g.Clear(Color.Plum)
g.DrawLine(myPen, 0, 0, 100, 100)
bmp.MakeTransparent(Color.Plum)
bmp.Save("TestFile.png", System.Drawing.Imaging.ImageFormat.Png)

Nov 21 '05 #2
Thanks, Ken, but that doesn't seem to do anything different. The
resulting .PNG image still appears on the web page as a light-grey
box.

On Mon, 17 Jan 2005 11:54:03 -0500, "Ken Tucker [MVP]"
<vb***@bellsouth.net> wrote:
Hi,

Try this instead.

Dim myPen As Pen = New Pen(Color.Green, 9)

Dim bmp As Bitmap = New Bitmap(100, 100)

Dim g As Graphics = Graphics.FromImage(bmp)

g.Clear(Color.Transparent)

g.DrawLine(myPen, 0, 0, 100, 100)

bmp.Save("TestFile.png", System.Drawing.Imaging.ImageFormat.Png)

Ken

------------------------

"Martin" <ma**********@comcast.net> wrote in message
news:i1********************************@4ax.com.. .
I'm using the code show below (in VB.Net 2003) to create an image. I
want to save this image to a .PNG file such that when I subsequently
display it as part of a web page, the background of the image will be
transparent.

This test/learning code simply draws a diagonal green line across a
square box. When I display the resulting file on a web page, I want
only the line itself to be visible but what is happening is that the
entire "box" is shown (in a light grey color) with the line drawn
across it.

Any suggestions as to how I can do this?

Thanks.

-----------------------------------------------------------
Dim myPen As Pen = New Pen(Color.Green, 9))
Dim bmp As Bitmap = New Bitmap(100, 100)
Dim g As Graphics = Graphics.FromImage(bmp)

g.Clear(Color.Plum)
g.DrawLine(myPen, 0, 0, 100, 100)
bmp.MakeTransparent(Color.Plum)
bmp.Save("TestFile.png", System.Drawing.Imaging.ImageFormat.Png)


Nov 21 '05 #3
"Martin" <ma**********@comcast.net> schrieb:
Thanks, Ken, but that doesn't seem to do anything different. The
resulting .PNG image still appears on the web page as a light-grey
box.


Notice that MSIE doesn't fully support transparent PNGs! Did you try to
open the file in explorer?

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #4
Martin wrote:
Thanks, Ken, but that doesn't seem to do anything different. The
resulting .PNG image still appears on the web page as a light-grey
box.

Internet Explorer doesn't support transparent PNGs, as far as I
can tell from the Web. So if your testing it using IE, you won't be
seeing what you should be.

On Mon, 17 Jan 2005 11:54:03 -0500, "Ken Tucker [MVP]"
<vb***@bellsouth.net> wrote:

Hi,

Try this instead.

Dim myPen As Pen = New Pen(Color.Green, 9)

Dim bmp As Bitmap = New Bitmap(100, 100)

Dim g As Graphics = Graphics.FromImage(bmp)

g.Clear(Color.Transparent)

g.DrawLine(myPen, 0, 0, 100, 100)

bmp.Save("TestFile.png", System.Drawing.Imaging.ImageFormat.Png)

Ken

------------------------

"Martin" <ma**********@comcast.net> wrote in message
news:i1********************************@4ax.com. ..
I'm using the code show below (in VB.Net 2003) to create an image. I
want to save this image to a .PNG file such that when I subsequently
display it as part of a web page, the background of the image will be
transparent.

This test/learning code simply draws a diagonal green line across a
square box. When I display the resulting file on a web page, I want
only the line itself to be visible but what is happening is that the
entire "box" is shown (in a light grey color) with the line drawn
across it.

Any suggestions as to how I can do this?

Thanks.

-----------------------------------------------------------
Dim myPen As Pen = New Pen(Color.Green, 9))
Dim bmp As Bitmap = New Bitmap(100, 100)
Dim g As Graphics = Graphics.FromImage(bmp)

g.Clear(Color.Plum)
g.DrawLine(myPen, 0, 0, 100, 100)
bmp.MakeTransparent(Color.Plum)
bmp.Save("TestFile.png", System.Drawing.Imaging.ImageFormat.Png)


Nov 21 '05 #5
Yes, I am using Internet Explorer. And, I wasn't aware that it had a
problem with transparent PNGs.

This is a big problem for me. I need to display these graphics (with
transparent backgrounds) in Internet Explorer. Do you have any
suggestions as to how I might accomplish that?

How about .GIF files - do you know if they would display correctly?

Any suggestions?

A bit of background: I currently have a series of web pages (that are
used only on an Intranet) that display some simple, created-on-the-fly
images. I'm doing this now by using VML (Vector Markup Language). I
have server-side scripts that create the VML statements as part of the
web page itself. The big problem is that VML is supported ONLY in
Internet Explorer (and it's a dead technology).

I'm experimenting with using some individual images and sending them
out as part of the web pages. My thinking is that such would be
viewable in ANY browser.
On Mon, 17 Jan 2005 17:24:58 +0000, Dominic Marks
<do*@helenmarks.co.uk> wrote:
Internet Explorer doesn't support transparent PNGs, as far as I
can tell from the Web. So if your testing it using IE, you won't be
seeing what you should be.


Nov 21 '05 #6
Well, I just tried it as a .gif file - that doesn't work either. The
image has a black background. :(
On Mon, 17 Jan 2005 10:46:43 -0700, Martin <ma**********@comcast.net>
wrote:
How about .GIF files - do you know if they would display correctly?


Nov 21 '05 #7
"Martin" <ma**********@comcast.net> schrieb:
How about .GIF files - do you know if they would display correctly?

GIF (and maybe transparent PNG8) support of MSIE is IMO better.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: dan glenn | last post by:
(PHP4.3.4, GD2) How can I save a PNG using GD2 and insure that it saves as a palette-based (8-bit, 256-color) single-color transparancy?? Saving this way, I could be sure that an image loaded from...
4
by: Dj Frenzy | last post by:
Hi, I know how to use javascript to change a background image to another background image, and how to change a background colour to another background colour. Is there a way to change an image to a...
3
by: Mark Tranchant | last post by:
On my site, I use a background image of a small arrow to denote links that lead away from my site. This page has four such links in the first section: http://tranchant.plus.com/notes/cable-wrap...
7
by: G .Net | last post by:
Hi I have a form on which I have a picture box. I have placed a GIF as the image for this picture box. The GIF has a transparent background. If I change the background color of the form, then...
4
by: rodchar | last post by:
hey all, i have an image that i want to put on my form and was just wondering if there is a way to take away the white background on the image (make it transparent)? thanks, rodchar
5
by: Dale | last post by:
When I create a System.Drawing.Bitmap and save it as ImageType.GIF, how can I set the transparency so that the background is transparent. In my application, the Bitmap that I am working with has...
4
by: Dale | last post by:
I am creating GIF images with transparent backgrounds on-the-fly for a web app and rendering them by using System.Drawing.Image.Save(Response.OutputStream, ImageType.GIF). I am confident that...
3
by: Angus | last post by:
I have a web page with a toolbar containing a Save button. The Save button can change contextually to be a Search button in some cases. Hence the button name searchsavechanges. The snippet of...
16
by: stevedude | last post by:
CSS newbie again. I have a problem trying to get coffee mug images within anchor tags to center with my link text for a vertical list menu. If I use the horizontal/vertical properties of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...

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.