473,789 Members | 2,408 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Transparency, ASP.NET, and GDI+

I am trying to create graphics with GDI+ that include transparency. However,
the transparency never seems to show up, even though my colors have an alpha
value of 0. How can I generate a graphic that is completely transparent in
certain areas (so that the web page background shows through)? I save my
graphics as gif files. I would appreciate, if possible, a simple example so
that I can see the code. Thanks.
--
Nathan Sokalski
nj********@hotm ail.com
http://www.nathansokalski.com/
Aug 11 '05
20 4525
Hi Nathan,

Okay, basically you have a palette to work with. The article tells you how
to define the colors in the palette. Also note that the palette can
certainly have LESS than 256 colors if you don't need them all. So, assuming
you're drawing with GDI+, you just clear the bitmap to the transparent
color, and draw with the others. All of the pixels that have the transparent
color will be transparent. It doesn't matter what the transparent color is;
it will be defined as "the transparent color" in the palette.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Expect the unaccepted.

"Nathan Sokalski" <nj********@hot mail.com> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
I looked at the article you mentioned, and it definitely cleared up for me
why I was never getting any transparency, but I am still having trouble
figuring out how to fix the problem. I think what I really need is just a
basic example that just draws a simple shape or two and then adds a
transparent area. (Preferably in VB.NET, but I can usually get enough from
C# that it helps enough to solve my problem) Thanks.
--
Nathan Sokalski
nj********@hotm ail.com
http://www.nathansokalski.com/

"Kevin Spencer" <ke***@DIESPAMM ERSDIEtakempis. com> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
Hi Nathan,

Sorry, I missed the "gif" reference in your OP.

A GIF image palette can define one color as transparent. I'm not sure how
you're defining the transparent color in your palette, but the following
Microsoft KB article explains how to do it. Note that the article is not
specifically about making a transparent gif, but it covers creating a
palette with a single transparent color, which is encoded as the
transparent color for the GIF:

http://support.microsoft.com/default...;EN-US;Q319061

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
Everybody picks their nose,
But some people are better at hiding it.

"Nathan Sokalski" <nj********@hot mail.com> wrote in message
news:On******** ******@TK2MSFTN GP14.phx.gbl...
Like I said in my original message, I am using GIF. The line that I use
to save my image is as follows (testbitmap is the name of my
System.Drawing. Bitmap object):

testbitmap.Save (Server.MapPath ("GDItest.gif") , Imaging.ImageFo rmat.Gif)

--
Nathan Sokalski
nj********@hotm ail.com
http://www.nathansokalski.com/

"Kevin Spencer" <ke***@DIESPAMM ERSDIEtakempis. com> wrote in message
news:eq******** ******@TK2MSFTN GP10.phx.gbl...
The only graphics formats that have transparency in HTML are GIF and
PNG. What format are you using?

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
Everybody picks their nose,
But some people are better at hiding it.

"Nathan Sokalski" <nj********@hot mail.com> wrote in message
news:Ot******** ******@TK2MSFTN GP10.phx.gbl...
>I am trying to create graphics with GDI+ that include transparency.
>However, the transparency never seems to show up, even though my colors
>have an alpha value of 0. How can I generate a graphic that is
>complete ly transparent in certain areas (so that the web page
>backgrou nd shows through)? I save my graphics as gif files. I would
>appreciate , if possible, a simple example so that I can see the code.
>Thanks.
> --
> Nathan Sokalski
> nj********@hotm ail.com
> http://www.nathansokalski.com/
>



Aug 12 '05 #11
oops.. GIF!
what about
Bitmap.MakeTran sparent (Color)
where Color is your background which might be white per default, I believe

--
If you're in a war, instead of throwing a hand grenade at the enemy, throw
one of those small pumpkins. Maybe it'll make everyone think how stupid war
is, and while they are thinking, you can throw a real grenade at them.
Jack Handey.
"Kevin Spencer" <ke***@DIESPAMM ERSDIEtakempis. com> wrote in message
news:Ol******** ******@TK2MSFTN GP12.phx.gbl...
Hi Nathan,

Okay, basically you have a palette to work with. The article tells you how
to define the colors in the palette. Also note that the palette can
certainly have LESS than 256 colors if you don't need them all. So,
assuming you're drawing with GDI+, you just clear the bitmap to the
transparent color, and draw with the others. All of the pixels that have
the transparent color will be transparent. It doesn't matter what the
transparent color is; it will be defined as "the transparent color" in the
palette.

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
Expect the unaccepted.

"Nathan Sokalski" <nj********@hot mail.com> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
I looked at the article you mentioned, and it definitely cleared up for me
why I was never getting any transparency, but I am still having trouble
figuring out how to fix the problem. I think what I really need is just a
basic example that just draws a simple shape or two and then adds a
transparent area. (Preferably in VB.NET, but I can usually get enough from
C# that it helps enough to solve my problem) Thanks.
--
Nathan Sokalski
nj********@hotm ail.com
http://www.nathansokalski.com/

"Kevin Spencer" <ke***@DIESPAMM ERSDIEtakempis. com> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
Hi Nathan,

Sorry, I missed the "gif" reference in your OP.

A GIF image palette can define one color as transparent. I'm not sure
how you're defining the transparent color in your palette, but the
following Microsoft KB article explains how to do it. Note that the
article is not specifically about making a transparent gif, but it
covers creating a palette with a single transparent color, which is
encoded as the transparent color for the GIF:

http://support.microsoft.com/default...;EN-US;Q319061

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
Everybody picks their nose,
But some people are better at hiding it.

"Nathan Sokalski" <nj********@hot mail.com> wrote in message
news:On******** ******@TK2MSFTN GP14.phx.gbl...
Like I said in my original message, I am using GIF. The line that I use
to save my image is as follows (testbitmap is the name of my
System.Drawing. Bitmap object):

testbitmap.Save (Server.MapPath ("GDItest.gif") , Imaging.ImageFo rmat.Gif)

--
Nathan Sokalski
nj********@hotm ail.com
http://www.nathansokalski.com/

"Kevin Spencer" <ke***@DIESPAMM ERSDIEtakempis. com> wrote in message
news:eq******** ******@TK2MSFTN GP10.phx.gbl...
> The only graphics formats that have transparency in HTML are GIF and
> PNG. What format are you using?
>
> --
> HTH,
>
> Kevin Spencer
> Microsoft MVP
> .Net Developer
> Everybody picks their nose,
> But some people are better at hiding it.
>
> "Nathan Sokalski" <nj********@hot mail.com> wrote in message
> news:Ot******** ******@TK2MSFTN GP10.phx.gbl...
>>I am trying to create graphics with GDI+ that include transparency.
>>However , the transparency never seems to show up, even though my
>>colors have an alpha value of 0. How can I generate a graphic that is
>>completel y transparent in certain areas (so that the web page
>>backgroun d shows through)? I save my graphics as gif files. I would
>>appreciat e, if possible, a simple example so that I can see the code.
>>Thanks.
>> --
>> Nathan Sokalski
>> nj********@hotm ail.com
>> http://www.nathansokalski.com/
>>
>
>



Aug 13 '05 #12
I am having trouble defining the colors in the palette. The first method I
tried gave me the error Object reference not set to an instance of an
object. (Which didn't surprise me, but it would not let me use the keyword
New when declaring the Imaging.ColorPa lette). Here is that code:

Dim transbitmap As New Bitmap(400, 400)
Dim transgraphics As Graphics = Graphics.FromIm age(transbitmap )
Dim transpen As New Pen(Color.FromA rgb(255, 0, 255, 0), 20)
Dim transbrush As New SolidBrush(Colo r.FromArgb(255, 255, 0, 0))
Dim transpalette As Imaging.ColorPa lette
transpalette.En tries(0) = Color.FromArgb( 0, 255, 255, 255)
transpalette.En tries(1) = Color.FromArgb( 255, 0, 255, 0)
transpalette.En tries(2) = Color.FromArgb( 255, 255, 0, 0)

transgraphics.C lear(Color.From Argb(0, 255, 255, 255))
transbitmap.Pal ette = transpalette
transgraphics.F illRectangle(tr ansbrush, 100, 100, 200, 200)
transgraphics.D rawRectangle(tr anspen, 50, 50, 150, 150)
transbitmap.Sav e(Server.MapPat h("GDItest.gif" ), Imaging.ImageFo rmat.Gif)
The second method I tried gave me the error Index was outside the bounds of
the array. Here is that code:

Dim transbitmap As New Bitmap(400, 400)
Dim transgraphics As Graphics = Graphics.FromIm age(transbitmap )
Dim transpen As New Pen(Color.FromA rgb(255, 0, 255, 0), 20)
Dim transbrush As New SolidBrush(Colo r.FromArgb(255, 255, 0, 0))
transbitmap.Pal ette.Entries(0) = Color.FromArgb( 0, 255, 255, 255)
transbitmap.Pal ette.Entries(1) = Color.FromArgb( 255, 0, 255, 0)
transbitmap.Pal ette.Entries(2) = Color.FromArgb( 255, 255, 0, 0)

transgraphics.C lear(Color.From Argb(0, 255, 255, 255))
transgraphics.F illRectangle(tr ansbrush, 100, 100, 200, 200)
transgraphics.D rawRectangle(tr anspen, 50, 50, 150, 150)
transbitmap.Sav e(Server.MapPat h("GDItest.gif" ), Imaging.ImageFo rmat.Gif)
What I expected from the code above was to create a GIF file with a red
filled rectangle, a green unfilled rectangle, and a transparent background.
If I remove the lines where I attempt to define the palette, this is what I
got except instead of a transparent background I ended up with a black
background. What am I supposed to do to create/edit the palette? The article
you mentioned took the palette from another Bitmap, which is not something I
am planning to do. Thanks.
--
Nathan Sokalski
nj********@hotm ail.com
http://www.nathansokalski.com/

"Kevin Spencer" <ke***@DIESPAMM ERSDIEtakempis. com> wrote in message
news:Ol******** ******@TK2MSFTN GP12.phx.gbl...
Hi Nathan,

Okay, basically you have a palette to work with. The article tells you how
to define the colors in the palette. Also note that the palette can
certainly have LESS than 256 colors if you don't need them all. So,
assuming you're drawing with GDI+, you just clear the bitmap to the
transparent color, and draw with the others. All of the pixels that have
the transparent color will be transparent. It doesn't matter what the
transparent color is; it will be defined as "the transparent color" in the
palette.

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
Expect the unaccepted.

"Nathan Sokalski" <nj********@hot mail.com> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
I looked at the article you mentioned, and it definitely cleared up for me
why I was never getting any transparency, but I am still having trouble
figuring out how to fix the problem. I think what I really need is just a
basic example that just draws a simple shape or two and then adds a
transparent area. (Preferably in VB.NET, but I can usually get enough from
C# that it helps enough to solve my problem) Thanks.
--
Nathan Sokalski
nj********@hotm ail.com
http://www.nathansokalski.com/

"Kevin Spencer" <ke***@DIESPAMM ERSDIEtakempis. com> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
Hi Nathan,

Sorry, I missed the "gif" reference in your OP.

A GIF image palette can define one color as transparent. I'm not sure
how you're defining the transparent color in your palette, but the
following Microsoft KB article explains how to do it. Note that the
article is not specifically about making a transparent gif, but it
covers creating a palette with a single transparent color, which is
encoded as the transparent color for the GIF:

http://support.microsoft.com/default...;EN-US;Q319061

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
Everybody picks their nose,
But some people are better at hiding it.

"Nathan Sokalski" <nj********@hot mail.com> wrote in message
news:On******** ******@TK2MSFTN GP14.phx.gbl...
Like I said in my original message, I am using GIF. The line that I use
to save my image is as follows (testbitmap is the name of my
System.Drawing. Bitmap object):

testbitmap.Save (Server.MapPath ("GDItest.gif") , Imaging.ImageFo rmat.Gif)

--
Nathan Sokalski
nj********@hotm ail.com
http://www.nathansokalski.com/

"Kevin Spencer" <ke***@DIESPAMM ERSDIEtakempis. com> wrote in message
news:eq******** ******@TK2MSFTN GP10.phx.gbl...
> The only graphics formats that have transparency in HTML are GIF and
> PNG. What format are you using?
>
> --
> HTH,
>
> Kevin Spencer
> Microsoft MVP
> .Net Developer
> Everybody picks their nose,
> But some people are better at hiding it.
>
> "Nathan Sokalski" <nj********@hot mail.com> wrote in message
> news:Ot******** ******@TK2MSFTN GP10.phx.gbl...
>>I am trying to create graphics with GDI+ that include transparency.
>>However , the transparency never seems to show up, even though my
>>colors have an alpha value of 0. How can I generate a graphic that is
>>completel y transparent in certain areas (so that the web page
>>backgroun d shows through)? I save my graphics as gif files. I would
>>appreciat e, if possible, a simple example so that I can see the code.
>>Thanks.
>> --
>> Nathan Sokalski
>> nj********@hotm ail.com
>> http://www.nathansokalski.com/
>>
>
>



Aug 13 '05 #13
I tried putting a color inside the MakeTransparent method, but it not only
did not make it transparent, but prevented all of the other stuff from being
drawn as well. Here is my code (note that the Clear method has the same
color as the MakeTransparent method):

Dim transbitmap As New Bitmap(400, 400)
Dim transgraphics As Graphics = Graphics.FromIm age(transbitmap )
Dim transpen As New Pen(Color.FromA rgb(255, 0, 255, 0), 20)
Dim transbrush As New SolidBrush(Colo r.FromArgb(255, 255, 0, 0))

transgraphics.C lear(Color.From Argb(0, 255, 255, 255))
transbitmap.Mak eTransparent(Co lor.FromArgb(0, 255, 255, 255))
transgraphics.F illRectangle(tr ansbrush, 100, 100, 200, 200)
transgraphics.D rawRectangle(tr anspen, 50, 50, 150, 150)
transbitmap.Sav e(Server.MapPat h("GDItest.gif" ), Imaging.ImageFo rmat.Gif)

Is there something wrong with the way I am using the MakeTransparent method?
What do I need to do to make areas of my image transparent? Thanks.
--
Nathan Sokalski
nj********@hotm ail.com
http://www.nathansokalski.com/

"Lloyd Dupont" <ld@NewsAccount .galador.net> wrote in message
news:Ox******** ******@tk2msftn gp13.phx.gbl...
oops.. GIF!
what about
Bitmap.MakeTran sparent (Color)
where Color is your background which might be white per default, I believe

--
If you're in a war, instead of throwing a hand grenade at the enemy, throw
one of those small pumpkins. Maybe it'll make everyone think how stupid
war is, and while they are thinking, you can throw a real grenade at them.
Jack Handey.
"Kevin Spencer" <ke***@DIESPAMM ERSDIEtakempis. com> wrote in message
news:Ol******** ******@TK2MSFTN GP12.phx.gbl...
Hi Nathan,

Okay, basically you have a palette to work with. The article tells you
how to define the colors in the palette. Also note that the palette can
certainly have LESS than 256 colors if you don't need them all. So,
assuming you're drawing with GDI+, you just clear the bitmap to the
transparent color, and draw with the others. All of the pixels that have
the transparent color will be transparent. It doesn't matter what the
transparent color is; it will be defined as "the transparent color" in
the palette.

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
Expect the unaccepted.

"Nathan Sokalski" <nj********@hot mail.com> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
I looked at the article you mentioned, and it definitely cleared up for
me why I was never getting any transparency, but I am still having
trouble figuring out how to fix the problem. I think what I really need
is just a basic example that just draws a simple shape or two and then
adds a transparent area. (Preferably in VB.NET, but I can usually get
enough from C# that it helps enough to solve my problem) Thanks.
--
Nathan Sokalski
nj********@hotm ail.com
http://www.nathansokalski.com/

"Kevin Spencer" <ke***@DIESPAMM ERSDIEtakempis. com> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
Hi Nathan,

Sorry, I missed the "gif" reference in your OP.

A GIF image palette can define one color as transparent. I'm not sure
how you're defining the transparent color in your palette, but the
following Microsoft KB article explains how to do it. Note that the
article is not specifically about making a transparent gif, but it
covers creating a palette with a single transparent color, which is
encoded as the transparent color for the GIF:

http://support.microsoft.com/default...;EN-US;Q319061

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
Everybody picks their nose,
But some people are better at hiding it.

"Nathan Sokalski" <nj********@hot mail.com> wrote in message
news:On******** ******@TK2MSFTN GP14.phx.gbl...
> Like I said in my original message, I am using GIF. The line that I
> use to save my image is as follows (testbitmap is the name of my
> System.Drawing. Bitmap object):
>
> testbitmap.Save (Server.MapPath ("GDItest.gif") ,
> Imaging.ImageFo rmat.Gif)
>
> --
> Nathan Sokalski
> nj********@hotm ail.com
> http://www.nathansokalski.com/
>
> "Kevin Spencer" <ke***@DIESPAMM ERSDIEtakempis. com> wrote in message
> news:eq******** ******@TK2MSFTN GP10.phx.gbl...
>> The only graphics formats that have transparency in HTML are GIF and
>> PNG. What format are you using?
>>
>> --
>> HTH,
>>
>> Kevin Spencer
>> Microsoft MVP
>> .Net Developer
>> Everybody picks their nose,
>> But some people are better at hiding it.
>>
>> "Nathan Sokalski" <nj********@hot mail.com> wrote in message
>> news:Ot******** ******@TK2MSFTN GP10.phx.gbl...
>>>I am trying to create graphics with GDI+ that include transparency.
>>>Howeve r, the transparency never seems to show up, even though my
>>>colors have an alpha value of 0. How can I generate a graphic that is
>>>complete ly transparent in certain areas (so that the web page
>>>backgrou nd shows through)? I save my graphics as gif files. I would
>>>apprecia te, if possible, a simple example so that I can see the code.
>>>Thanks .
>>> --
>>> Nathan Sokalski
>>> nj********@hotm ail.com
>>> http://www.nathansokalski.com/
>>>
>>
>>
>
>



Aug 13 '05 #14
GWBYF (aka Google Would Be Your Friend != RTFM)
http://www.bobpowell.net/giftransparency.htm

--
If you're in a war, instead of throwing a hand grenade at the enemy, throw
one of those small pumpkins. Maybe it'll make everyone think how stupid war
is, and while they are thinking, you can throw a real grenade at them.
Jack Handey.
"Nathan Sokalski" <nj********@hot mail.com> wrote in message
news:%2******** ********@TK2MSF TNGP15.phx.gbl. ..
I tried putting a color inside the MakeTransparent method, but it not only
did not make it transparent, but prevented all of the other stuff from
being drawn as well. Here is my code (note that the Clear method has the
same color as the MakeTransparent method):

Dim transbitmap As New Bitmap(400, 400)
Dim transgraphics As Graphics = Graphics.FromIm age(transbitmap )
Dim transpen As New Pen(Color.FromA rgb(255, 0, 255, 0), 20)
Dim transbrush As New SolidBrush(Colo r.FromArgb(255, 255, 0, 0))

transgraphics.C lear(Color.From Argb(0, 255, 255, 255))
transbitmap.Mak eTransparent(Co lor.FromArgb(0, 255, 255, 255))
transgraphics.F illRectangle(tr ansbrush, 100, 100, 200, 200)
transgraphics.D rawRectangle(tr anspen, 50, 50, 150, 150)
transbitmap.Sav e(Server.MapPat h("GDItest.gif" ), Imaging.ImageFo rmat.Gif)

Is there something wrong with the way I am using the MakeTransparent
method? What do I need to do to make areas of my image transparent?
Thanks.
--
Nathan Sokalski
nj********@hotm ail.com
http://www.nathansokalski.com/

"Lloyd Dupont" <ld@NewsAccount .galador.net> wrote in message
news:Ox******** ******@tk2msftn gp13.phx.gbl...
oops.. GIF!
what about
Bitmap.MakeTran sparent (Color)
where Color is your background which might be white per default, I
believe

--
If you're in a war, instead of throwing a hand grenade at the enemy,
throw one of those small pumpkins. Maybe it'll make everyone think how
stupid war is, and while they are thinking, you can throw a real grenade
at them.
Jack Handey.
"Kevin Spencer" <ke***@DIESPAMM ERSDIEtakempis. com> wrote in message
news:Ol******** ******@TK2MSFTN GP12.phx.gbl...
Hi Nathan,

Okay, basically you have a palette to work with. The article tells you
how to define the colors in the palette. Also note that the palette can
certainly have LESS than 256 colors if you don't need them all. So,
assuming you're drawing with GDI+, you just clear the bitmap to the
transparent color, and draw with the others. All of the pixels that have
the transparent color will be transparent. It doesn't matter what the
transparent color is; it will be defined as "the transparent color" in
the palette.

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
Expect the unaccepted.

"Nathan Sokalski" <nj********@hot mail.com> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
I looked at the article you mentioned, and it definitely cleared up for
me why I was never getting any transparency, but I am still having
trouble figuring out how to fix the problem. I think what I really need
is just a basic example that just draws a simple shape or two and then
adds a transparent area. (Preferably in VB.NET, but I can usually get
enough from C# that it helps enough to solve my problem) Thanks.
--
Nathan Sokalski
nj********@hotm ail.com
http://www.nathansokalski.com/

"Kevin Spencer" <ke***@DIESPAMM ERSDIEtakempis. com> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
> Hi Nathan,
>
> Sorry, I missed the "gif" reference in your OP.
>
> A GIF image palette can define one color as transparent. I'm not sure
> how you're defining the transparent color in your palette, but the
> following Microsoft KB article explains how to do it. Note that the
> article is not specifically about making a transparent gif, but it
> covers creating a palette with a single transparent color, which is
> encoded as the transparent color for the GIF:
>
> http://support.microsoft.com/default...;EN-US;Q319061
>
> --
> HTH,
>
> Kevin Spencer
> Microsoft MVP
> .Net Developer
> Everybody picks their nose,
> But some people are better at hiding it.
>
> "Nathan Sokalski" <nj********@hot mail.com> wrote in message
> news:On******** ******@TK2MSFTN GP14.phx.gbl...
>> Like I said in my original message, I am using GIF. The line that I
>> use to save my image is as follows (testbitmap is the name of my
>> System.Drawing. Bitmap object):
>>
>> testbitmap.Save (Server.MapPath ("GDItest.gif") ,
>> Imaging.ImageFo rmat.Gif)
>>
>> --
>> Nathan Sokalski
>> nj********@hotm ail.com
>> http://www.nathansokalski.com/
>>
>> "Kevin Spencer" <ke***@DIESPAMM ERSDIEtakempis. com> wrote in message
>> news:eq******** ******@TK2MSFTN GP10.phx.gbl...
>>> The only graphics formats that have transparency in HTML are GIF and
>>> PNG. What format are you using?
>>>
>>> --
>>> HTH,
>>>
>>> Kevin Spencer
>>> Microsoft MVP
>>> .Net Developer
>>> Everybody picks their nose,
>>> But some people are better at hiding it.
>>>
>>> "Nathan Sokalski" <nj********@hot mail.com> wrote in message
>>> news:Ot******** ******@TK2MSFTN GP10.phx.gbl...
>>>>I am trying to create graphics with GDI+ that include transparency.
>>>>However , the transparency never seems to show up, even though my
>>>>color s have an alpha value of 0. How can I generate a graphic that
>>>>is completely transparent in certain areas (so that the web page
>>>>backgro und shows through)? I save my graphics as gif files. I would
>>>>appreci ate, if possible, a simple example so that I can see the
>>>>code. Thanks.
>>>> --
>>>> Nathan Sokalski
>>>> nj********@hotm ail.com
>>>> http://www.nathansokalski.com/
>>>>
>>>
>>>
>>
>>
>
>



Aug 13 '05 #15
I have tried searching (I've spent almost 2 months trying to find an
answer), but none of the stuff I found seemed to help.
--
Nathan Sokalski
nj********@hotm ail.com
http://www.nathansokalski.com/

"Lloyd Dupont" <ld@NewsAccount .galador.net> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
GWBYF (aka Google Would Be Your Friend != RTFM)
http://www.bobpowell.net/giftransparency.htm

--
If you're in a war, instead of throwing a hand grenade at the enemy, throw
one of those small pumpkins. Maybe it'll make everyone think how stupid
war is, and while they are thinking, you can throw a real grenade at them.
Jack Handey.
"Nathan Sokalski" <nj********@hot mail.com> wrote in message
news:%2******** ********@TK2MSF TNGP15.phx.gbl. ..
I tried putting a color inside the MakeTransparent method, but it not only
did not make it transparent, but prevented all of the other stuff from
being drawn as well. Here is my code (note that the Clear method has the
same color as the MakeTransparent method):

Dim transbitmap As New Bitmap(400, 400)
Dim transgraphics As Graphics = Graphics.FromIm age(transbitmap )
Dim transpen As New Pen(Color.FromA rgb(255, 0, 255, 0), 20)
Dim transbrush As New SolidBrush(Colo r.FromArgb(255, 255, 0, 0))

transgraphics.C lear(Color.From Argb(0, 255, 255, 255))
transbitmap.Mak eTransparent(Co lor.FromArgb(0, 255, 255, 255))
transgraphics.F illRectangle(tr ansbrush, 100, 100, 200, 200)
transgraphics.D rawRectangle(tr anspen, 50, 50, 150, 150)
transbitmap.Sav e(Server.MapPat h("GDItest.gif" ), Imaging.ImageFo rmat.Gif)

Is there something wrong with the way I am using the MakeTransparent
method? What do I need to do to make areas of my image transparent?
Thanks.
--
Nathan Sokalski
nj********@hotm ail.com
http://www.nathansokalski.com/

"Lloyd Dupont" <ld@NewsAccount .galador.net> wrote in message
news:Ox******** ******@tk2msftn gp13.phx.gbl...
oops.. GIF!
what about
Bitmap.MakeTran sparent (Color)
where Color is your background which might be white per default, I
believe

--
If you're in a war, instead of throwing a hand grenade at the enemy,
throw one of those small pumpkins. Maybe it'll make everyone think how
stupid war is, and while they are thinking, you can throw a real grenade
at them.
Jack Handey.
"Kevin Spencer" <ke***@DIESPAMM ERSDIEtakempis. com> wrote in message
news:Ol******** ******@TK2MSFTN GP12.phx.gbl...
Hi Nathan,

Okay, basically you have a palette to work with. The article tells you
how to define the colors in the palette. Also note that the palette can
certainly have LESS than 256 colors if you don't need them all. So,
assuming you're drawing with GDI+, you just clear the bitmap to the
transparent color, and draw with the others. All of the pixels that
have the transparent color will be transparent. It doesn't matter what
the transparent color is; it will be defined as "the transparent color"
in the palette.

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
Expect the unaccepted.

"Nathan Sokalski" <nj********@hot mail.com> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
>I looked at the article you mentioned, and it definitely cleared up for
>me why I was never getting any transparency, but I am still having
>trouble figuring out how to fix the problem. I think what I really need
>is just a basic example that just draws a simple shape or two and then
>adds a transparent area. (Preferably in VB.NET, but I can usually get
>enough from C# that it helps enough to solve my problem) Thanks.
> --
> Nathan Sokalski
> nj********@hotm ail.com
> http://www.nathansokalski.com/
>
> "Kevin Spencer" <ke***@DIESPAMM ERSDIEtakempis. com> wrote in message
> news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
>> Hi Nathan,
>>
>> Sorry, I missed the "gif" reference in your OP.
>>
>> A GIF image palette can define one color as transparent. I'm not sure
>> how you're defining the transparent color in your palette, but the
>> following Microsoft KB article explains how to do it. Note that the
>> article is not specifically about making a transparent gif, but it
>> covers creating a palette with a single transparent color, which is
>> encoded as the transparent color for the GIF:
>>
>> http://support.microsoft.com/default...;EN-US;Q319061
>>
>> --
>> HTH,
>>
>> Kevin Spencer
>> Microsoft MVP
>> .Net Developer
>> Everybody picks their nose,
>> But some people are better at hiding it.
>>
>> "Nathan Sokalski" <nj********@hot mail.com> wrote in message
>> news:On******** ******@TK2MSFTN GP14.phx.gbl...
>>> Like I said in my original message, I am using GIF. The line that I
>>> use to save my image is as follows (testbitmap is the name of my
>>> System.Drawing. Bitmap object):
>>>
>>> testbitmap.Save (Server.MapPath ("GDItest.gif") ,
>>> Imaging.ImageFo rmat.Gif)
>>>
>>> --
>>> Nathan Sokalski
>>> nj********@hotm ail.com
>>> http://www.nathansokalski.com/
>>>
>>> "Kevin Spencer" <ke***@DIESPAMM ERSDIEtakempis. com> wrote in message
>>> news:eq******** ******@TK2MSFTN GP10.phx.gbl...
>>>> The only graphics formats that have transparency in HTML are GIF
>>>> and PNG. What format are you using?
>>>>
>>>> --
>>>> HTH,
>>>>
>>>> Kevin Spencer
>>>> Microsoft MVP
>>>> .Net Developer
>>>> Everybody picks their nose,
>>>> But some people are better at hiding it.
>>>>
>>>> "Nathan Sokalski" <nj********@hot mail.com> wrote in message
>>>> news:Ot******** ******@TK2MSFTN GP10.phx.gbl...
>>>>>I am trying to create graphics with GDI+ that include transparency.
>>>>>Howeve r, the transparency never seems to show up, even though my
>>>>>colo rs have an alpha value of 0. How can I generate a graphic that
>>>>>is completely transparent in certain areas (so that the web page
>>>>>backgr ound shows through)? I save my graphics as gif files. I would
>>>>>apprec iate, if possible, a simple example so that I can see the
>>>>>code . Thanks.
>>>>> --
>>>>> Nathan Sokalski
>>>>> nj********@hotm ail.com
>>>>> http://www.nathansokalski.com/
>>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>
>



Aug 13 '05 #16
allright, allright, but have you checked the link I posted as well?
(this one: http://www.bobpowell.net/giftransparency.htm)
should fix it!

"Nathan Sokalski" <nj********@hot mail.com> wrote in message >I have tried
searching (I've spent almost 2 months trying to find an
answer), but none of the stuff I found seemed to help.
--

"Lloyd Dupont" <ld@NewsAccount .galador.net> wrote in message
GWBYF (aka Google Would Be Your Friend != RTFM)
http://www.bobpowell.net/giftransparency.htm

Aug 13 '05 #17
Bitmap Transparency is not supported in browsers. Only GIFs and PNGs are
transparent, and only GIFs are universally transparent in browsers. The
article I sent you to doesn't use BitMap.MakeTran sparent(). I am not sure
why you keep bringing this up. It is a simple matter of following
instructions. The functions you use in your app are not a goal, but should
only be used if they are a means TO your goal. Let's say you're baking a
cake. Why on earth would you need or want to use a meat grinder in the
process? A meat grinder is for grinding meat, not for baking a cake.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Expect the unaccepted.

"Lloyd Dupont" <ld@NewsAccount .galador.net> wrote in message
news:Ox******** ******@tk2msftn gp13.phx.gbl...
oops.. GIF!
what about
Bitmap.MakeTran sparent (Color)
where Color is your background which might be white per default, I believe

--
If you're in a war, instead of throwing a hand grenade at the enemy, throw
one of those small pumpkins. Maybe it'll make everyone think how stupid
war is, and while they are thinking, you can throw a real grenade at them.
Jack Handey.
"Kevin Spencer" <ke***@DIESPAMM ERSDIEtakempis. com> wrote in message
news:Ol******** ******@TK2MSFTN GP12.phx.gbl...
Hi Nathan,

Okay, basically you have a palette to work with. The article tells you
how to define the colors in the palette. Also note that the palette can
certainly have LESS than 256 colors if you don't need them all. So,
assuming you're drawing with GDI+, you just clear the bitmap to the
transparent color, and draw with the others. All of the pixels that have
the transparent color will be transparent. It doesn't matter what the
transparent color is; it will be defined as "the transparent color" in
the palette.

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
Expect the unaccepted.

"Nathan Sokalski" <nj********@hot mail.com> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
I looked at the article you mentioned, and it definitely cleared up for
me why I was never getting any transparency, but I am still having
trouble figuring out how to fix the problem. I think what I really need
is just a basic example that just draws a simple shape or two and then
adds a transparent area. (Preferably in VB.NET, but I can usually get
enough from C# that it helps enough to solve my problem) Thanks.
--
Nathan Sokalski
nj********@hotm ail.com
http://www.nathansokalski.com/

"Kevin Spencer" <ke***@DIESPAMM ERSDIEtakempis. com> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
Hi Nathan,

Sorry, I missed the "gif" reference in your OP.

A GIF image palette can define one color as transparent. I'm not sure
how you're defining the transparent color in your palette, but the
following Microsoft KB article explains how to do it. Note that the
article is not specifically about making a transparent gif, but it
covers creating a palette with a single transparent color, which is
encoded as the transparent color for the GIF:

http://support.microsoft.com/default...;EN-US;Q319061

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
Everybody picks their nose,
But some people are better at hiding it.

"Nathan Sokalski" <nj********@hot mail.com> wrote in message
news:On******** ******@TK2MSFTN GP14.phx.gbl...
> Like I said in my original message, I am using GIF. The line that I
> use to save my image is as follows (testbitmap is the name of my
> System.Drawing. Bitmap object):
>
> testbitmap.Save (Server.MapPath ("GDItest.gif") ,
> Imaging.ImageFo rmat.Gif)
>
> --
> Nathan Sokalski
> nj********@hotm ail.com
> http://www.nathansokalski.com/
>
> "Kevin Spencer" <ke***@DIESPAMM ERSDIEtakempis. com> wrote in message
> news:eq******** ******@TK2MSFTN GP10.phx.gbl...
>> The only graphics formats that have transparency in HTML are GIF and
>> PNG. What format are you using?
>>
>> --
>> HTH,
>>
>> Kevin Spencer
>> Microsoft MVP
>> .Net Developer
>> Everybody picks their nose,
>> But some people are better at hiding it.
>>
>> "Nathan Sokalski" <nj********@hot mail.com> wrote in message
>> news:Ot******** ******@TK2MSFTN GP10.phx.gbl...
>>>I am trying to create graphics with GDI+ that include transparency.
>>>Howeve r, the transparency never seems to show up, even though my
>>>colors have an alpha value of 0. How can I generate a graphic that is
>>>complete ly transparent in certain areas (so that the web page
>>>backgrou nd shows through)? I save my graphics as gif files. I would
>>>apprecia te, if possible, a simple example so that I can see the code.
>>>Thanks .
>>> --
>>> Nathan Sokalski
>>> nj********@hotm ail.com
>>> http://www.nathansokalski.com/
>>>
>>
>>
>
>



Aug 15 '05 #18
Check out the sample code from the article I referred to you:

protected ColorPalette GetColorPalette ( uint nColors )
{
// Assume monochrome image.
PixelFormat bitscolordepth = PixelFormat.For mat1bppIndexed;
ColorPalette palette; // The Palette we are stealing
Bitmap bitmap; // The source of the stolen palette

// Determine number of colors.
if (nColors > 2)
bitscolordepth = PixelFormat.For mat4bppIndexed;
if (nColors > 16)
bitscolordepth = PixelFormat.For mat8bppIndexed;

// Make a new Bitmap object to get its Palette.
bitmap = new Bitmap( 1, 1, bitscolordepth );

palette = bitmap.Palette; // Grab the palette

bitmap.Dispose( ); // cleanup the source Bitmap

return palette; // Send the palette back
}

That doesn't look anything like what you wrote, regardless of the language.
The palette is retrieved from a Bitmap of a specific paletted format. Are
you having trouble translating from C# to VB? If so, I can do it for you.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Expect the unaccepted.

"Nathan Sokalski" <nj********@hot mail.com> wrote in message
news:eU******** ******@TK2MSFTN GP15.phx.gbl...
I am having trouble defining the colors in the palette. The first method I
tried gave me the error Object reference not set to an instance of an
object. (Which didn't surprise me, but it would not let me use the keyword
New when declaring the Imaging.ColorPa lette). Here is that code:

Dim transbitmap As New Bitmap(400, 400)
Dim transgraphics As Graphics = Graphics.FromIm age(transbitmap )
Dim transpen As New Pen(Color.FromA rgb(255, 0, 255, 0), 20)
Dim transbrush As New SolidBrush(Colo r.FromArgb(255, 255, 0, 0))
Dim transpalette As Imaging.ColorPa lette
transpalette.En tries(0) = Color.FromArgb( 0, 255, 255, 255)
transpalette.En tries(1) = Color.FromArgb( 255, 0, 255, 0)
transpalette.En tries(2) = Color.FromArgb( 255, 255, 0, 0)

transgraphics.C lear(Color.From Argb(0, 255, 255, 255))
transbitmap.Pal ette = transpalette
transgraphics.F illRectangle(tr ansbrush, 100, 100, 200, 200)
transgraphics.D rawRectangle(tr anspen, 50, 50, 150, 150)
transbitmap.Sav e(Server.MapPat h("GDItest.gif" ), Imaging.ImageFo rmat.Gif)
The second method I tried gave me the error Index was outside the bounds
of the array. Here is that code:

Dim transbitmap As New Bitmap(400, 400)
Dim transgraphics As Graphics = Graphics.FromIm age(transbitmap )
Dim transpen As New Pen(Color.FromA rgb(255, 0, 255, 0), 20)
Dim transbrush As New SolidBrush(Colo r.FromArgb(255, 255, 0, 0))
transbitmap.Pal ette.Entries(0) = Color.FromArgb( 0, 255, 255, 255)
transbitmap.Pal ette.Entries(1) = Color.FromArgb( 255, 0, 255, 0)
transbitmap.Pal ette.Entries(2) = Color.FromArgb( 255, 255, 0, 0)

transgraphics.C lear(Color.From Argb(0, 255, 255, 255))
transgraphics.F illRectangle(tr ansbrush, 100, 100, 200, 200)
transgraphics.D rawRectangle(tr anspen, 50, 50, 150, 150)
transbitmap.Sav e(Server.MapPat h("GDItest.gif" ), Imaging.ImageFo rmat.Gif)
What I expected from the code above was to create a GIF file with a red
filled rectangle, a green unfilled rectangle, and a transparent
background. If I remove the lines where I attempt to define the palette,
this is what I got except instead of a transparent background I ended up
with a black background. What am I supposed to do to create/edit the
palette? The article you mentioned took the palette from another Bitmap,
which is not something I am planning to do. Thanks.
--
Nathan Sokalski
nj********@hotm ail.com
http://www.nathansokalski.com/

"Kevin Spencer" <ke***@DIESPAMM ERSDIEtakempis. com> wrote in message
news:Ol******** ******@TK2MSFTN GP12.phx.gbl...
Hi Nathan,

Okay, basically you have a palette to work with. The article tells you
how to define the colors in the palette. Also note that the palette can
certainly have LESS than 256 colors if you don't need them all. So,
assuming you're drawing with GDI+, you just clear the bitmap to the
transparent color, and draw with the others. All of the pixels that have
the transparent color will be transparent. It doesn't matter what the
transparent color is; it will be defined as "the transparent color" in
the palette.

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
Expect the unaccepted.

"Nathan Sokalski" <nj********@hot mail.com> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
I looked at the article you mentioned, and it definitely cleared up for
me why I was never getting any transparency, but I am still having
trouble figuring out how to fix the problem. I think what I really need
is just a basic example that just draws a simple shape or two and then
adds a transparent area. (Preferably in VB.NET, but I can usually get
enough from C# that it helps enough to solve my problem) Thanks.
--
Nathan Sokalski
nj********@hotm ail.com
http://www.nathansokalski.com/

"Kevin Spencer" <ke***@DIESPAMM ERSDIEtakempis. com> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
Hi Nathan,

Sorry, I missed the "gif" reference in your OP.

A GIF image palette can define one color as transparent. I'm not sure
how you're defining the transparent color in your palette, but the
following Microsoft KB article explains how to do it. Note that the
article is not specifically about making a transparent gif, but it
covers creating a palette with a single transparent color, which is
encoded as the transparent color for the GIF:

http://support.microsoft.com/default...;EN-US;Q319061

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
Everybody picks their nose,
But some people are better at hiding it.

"Nathan Sokalski" <nj********@hot mail.com> wrote in message
news:On******** ******@TK2MSFTN GP14.phx.gbl...
> Like I said in my original message, I am using GIF. The line that I
> use to save my image is as follows (testbitmap is the name of my
> System.Drawing. Bitmap object):
>
> testbitmap.Save (Server.MapPath ("GDItest.gif") ,
> Imaging.ImageFo rmat.Gif)
>
> --
> Nathan Sokalski
> nj********@hotm ail.com
> http://www.nathansokalski.com/
>
> "Kevin Spencer" <ke***@DIESPAMM ERSDIEtakempis. com> wrote in message
> news:eq******** ******@TK2MSFTN GP10.phx.gbl...
>> The only graphics formats that have transparency in HTML are GIF and
>> PNG. What format are you using?
>>
>> --
>> HTH,
>>
>> Kevin Spencer
>> Microsoft MVP
>> .Net Developer
>> Everybody picks their nose,
>> But some people are better at hiding it.
>>
>> "Nathan Sokalski" <nj********@hot mail.com> wrote in message
>> news:Ot******** ******@TK2MSFTN GP10.phx.gbl...
>>>I am trying to create graphics with GDI+ that include transparency.
>>>Howeve r, the transparency never seems to show up, even though my
>>>colors have an alpha value of 0. How can I generate a graphic that is
>>>complete ly transparent in certain areas (so that the web page
>>>backgrou nd shows through)? I save my graphics as gif files. I would
>>>apprecia te, if possible, a simple example so that I can see the code.
>>>Thanks .
>>> --
>>> Nathan Sokalski
>>> nj********@hotm ail.com
>>> http://www.nathansokalski.com/
>>>
>>
>>
>
>



Aug 15 '05 #19
Martin Bourbonnais
1 New Member
Dim myBitmap As New Bitmap("Grapes. gif")
' Get the color of a background pixel.
Dim backColor As Color = myBitmap.GetPix el(1, 1)
' Make backColor transparent for myBitmap.
myBitmap.MakeTr ansparent(backC olor)
Aug 18 '05 #20

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

Similar topics

19
1486
by: Nathan Sokalski | last post by:
I am trying to create graphics with GDI+ that include transparency. However, the transparency never seems to show up, even though my colors have an alpha value of 0. How can I generate a graphic that is completely transparent in certain areas (so that the web page background shows through)? I save my graphics as gif files. I would appreciate, if possible, a simple example so that I can see the code. Thanks. -- Nathan Sokalski...
6
3655
by: tommaso.gastaldi | last post by:
In a previous post I have been asking about a way to test Alpha Transparency. Bob and Michael have kindly provided some ideas. Here I would like to share the function I have prepared, for the purpose to improve it. Frankly, I am not clear about the exact meaning of some pixel format (max, gdi, etc.) and I hope I have put them under the right "case". I have made only some superficial test and it seems to work. Note that the purpose is...
0
9663
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
9506
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10404
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
10193
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
10136
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
6761
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5415
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...
1
4089
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
2
3695
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.