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) | | | | re: Save image to .PNG with transparent background?
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" <martinvalley@comcast.net> wrote in message
news:i1qnu099e03q9ajqvs72uk8n2flvm4j1e1@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) | | | | re: Save image to .PNG with transparent background?
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]"
<vb2ae@bellsouth.net> wrote:
[color=blue]
>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" <martinvalley@comcast.net> wrote in message
>news:i1qnu099e03q9ajqvs72uk8n2flvm4j1e1@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)
>
>[/color] | | | | re: Save image to .PNG with transparent background?
"Martin" <martinvalley@comcast.net> schrieb:[color=blue]
> 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.[/color]
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/> | | | | re: Save image to .PNG with transparent background?
Martin wrote:[color=blue]
> 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.
>[/color]
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.
[color=blue]
>
> On Mon, 17 Jan 2005 11:54:03 -0500, "Ken Tucker [MVP]"
> <vb2ae@bellsouth.net> wrote:
>
>[color=green]
>>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" <martinvalley@comcast.net> wrote in message
>>news:i1qnu099e03q9ajqvs72uk8n2flvm4j1e1@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)
>>
>>[/color]
>
>[/color] | | | | re: Save image to .PNG with transparent background?
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
<dom@helenmarks.co.uk> wrote:
[color=blue]
>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.[/color] | | | | re: Save image to .PNG with transparent background?
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 <martinvalley@comcast.net>
wrote:
[color=blue]
>How about .GIF files - do you know if they would display correctly?[/color] | | | | re: Save image to .PNG with transparent background?
"Martin" <martinvalley@comcast.net> schrieb:[color=blue]
> How about .GIF files - do you know if they would display correctly?[/color]
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/> |  | Similar Visual Basic .NET bytes | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,295 network members.
|