--
HTH,
Kevin Spencer
Microsoft MVP
.Net Developer
Everybody picks their nose,
But some people are better at hiding it.
"Nathan Sokalski" <njsok...@hotmail.com> wrote in message
news:OtgRhOqn...@TK2MSFTNGP10.phx.gbl...
testbitmap.Save(Server.MapPath("GDItest.gif"), Imaging.ImageFormat.Gif)
--
Nathan Sokalski
njsok...@hotmail.com
http://www.nathansokalski.com/
"Kevin Spencer" <ke...@DIESPAMMERSDIEtakempis.com> wrote in message
news:eq$BVdrnF...@TK2MSFTNGP10.phx.gbl...
"Nathan Sokalski" <njsok...@hotmail.com> wrote in message
news:On0xnMtn...@TK2MSFTNGP14.phx.gbl...
"Lloyd Dupont" <net.galador@ld> wrote in message
news:eyb0iUun...@TK2MSFTNGP09.phx.gbl...
Bitmap bmp = new Bitmap(width, height);
bmp.MakeTransparent();
or with
bmp.LockBit() you could directly access the bitmap's color pointer
as explained here:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dncscol/html/csharp11152001.asp
--
HTH,
Kevin Spencer
Microsoft MVP
.Net Developer
Everybody picks their nose,
But some people are better at hiding it.
"Lloyd Dupont" <net.galador@ld> wrote in message
news:eyb0iUun...@TK2MSFTNGP09.phx.gbl...
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.aspx?scid=kb;EN-US;Q319061
--
HTH,
Kevin Spencer
Microsoft MVP
.Net Developer
Everybody picks their nose,
But some people are better at hiding it.
"Nathan Sokalski" <njsok...@hotmail.com> wrote in message
news:On0xnMtn...@TK2MSFTNGP14.phx.gbl...
"Lloyd Dupont" <net.galador@ld> wrote in message
news:OMrxPhvn...@tk2msftngp13.phx.gbl...
"Kevin Spencer" <ke...@DIESPAMMERSDIEtakempis.com> wrote in message
news:%2335It9y...@TK2MSFTNGP12.phx.gbl...
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" <njsok...@hotmail.com> wrote in message
news:%23daSLW3...@TK2MSFTNGP10.phx.gbl...
--
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...@DIESPAMMERSDIEtakempis.com> wrote in message
news:OlQAv83n...@TK2MSFTNGP12.phx.gbl...
Dim transbitmap As New Bitmap(400, 400)
Dim transgraphics As Graphics = Graphics.FromImage(transbitmap)
Dim transpen As New Pen(Color.FromArgb(255, 0, 255, 0), 20)
Dim transbrush As New SolidBrush(Color.FromArgb(255, 255, 0, 0))
Dim transpalette As Imaging.ColorPalette
transpalette.Entries(0) = Color.FromArgb(0, 255, 255, 255)
transpalette.Entries(1) = Color.FromArgb(255, 0, 255, 0)
transpalette.Entries(2) = Color.FromArgb(255, 255, 0, 0)
transgraphics.Clear(Color.FromArgb(0, 255, 255, 255))
transbitmap.Palette = transpalette
transgraphics.FillRectangle(transbrush, 100, 100, 200, 200)
transgraphics.DrawRectangle(transpen, 50, 50, 150, 150)
transbitmap.Save(Server.MapPath("GDItest.gif"), Imaging.ImageFormat.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.FromImage(transbitmap)
Dim transpen As New Pen(Color.FromArgb(255, 0, 255, 0), 20)
Dim transbrush As New SolidBrush(Color.FromArgb(255, 255, 0, 0))
transbitmap.Palette.Entries(0) = Color.FromArgb(0, 255, 255, 255)
transbitmap.Palette.Entries(1) = Color.FromArgb(255, 0, 255, 0)
transbitmap.Palette.Entries(2) = Color.FromArgb(255, 255, 0, 0)
transgraphics.Clear(Color.FromArgb(0, 255, 255, 255))
transgraphics.FillRectangle(transbrush, 100, 100, 200, 200)
transgraphics.DrawRectangle(transpen, 50, 50, 150, 150)
transbitmap.Save(Server.MapPath("GDItest.gif"), Imaging.ImageFormat.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
njsok...@hotmail.com
http://www.nathansokalski.com/
"Kevin Spencer" <ke...@DIESPAMMERSDIEtakempis.com> wrote in message
news:OlQAv83n...@TK2MSFTNGP12.phx.gbl...
Dim transbitmap As New Bitmap(400, 400)
Dim transgraphics As Graphics = Graphics.FromImage(transbitmap)
Dim transpen As New Pen(Color.FromArgb(255, 0, 255, 0), 20)
Dim transbrush As New SolidBrush(Color.FromArgb(255, 255, 0, 0))
transgraphics.Clear(Color.FromArgb(0, 255, 255, 255))
transbitmap.MakeTransparent(Color.FromArgb(0, 255, 255, 255))
transgraphics.FillRectangle(transbrush, 100, 100, 200, 200)
transgraphics.DrawRectangle(transpen, 50, 50, 150, 150)
transbitmap.Save(Server.MapPath("GDItest.gif"), Imaging.ImageFormat.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
njsok...@hotmail.com
http://www.nathansokalski.com/
"Lloyd Dupont" <l...@NewsAccount.galador.net> wrote in message
news:OxeBOj5n...@tk2msftngp13.phx.gbl...
--
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" <njsok...@hotmail.com> wrote in message
news:%23SuMEt6...@TK2MSFTNGP15.phx.gbl...
"Lloyd Dupont" <l...@NewsAccount.galador.net> wrote in message
news:%23v1Z$y7nFH...@TK2MSFTNGP12.phx.gbl...
"Nathan Sokalski" <njsok...@hotmail.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" <l...@NewsAccount.galador.net> wrote in message
--
HTH,
Kevin Spencer
Microsoft MVP
.Net Developer
Expect the unaccepted.
"Lloyd Dupont" <l...@NewsAccount.galador.net> wrote in message
news:OxeBOj5n...@tk2msftngp13.phx.gbl...
protected ColorPalette GetColorPalette( uint nColors )
{
// Assume monochrome image.
PixelFormat bitscolordepth = PixelFormat.Format1bppIndexed;
ColorPalette palette; // The Palette we are stealing
Bitmap bitmap; // The source of the stolen palette
// Determine number of colors.
if (nColors > 2)
bitscolordepth = PixelFormat.Format4bppIndexed;
if (nColors > 16)
bitscolordepth = PixelFormat.Format8bppIndexed;
// 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" <njsok...@hotmail.com> wrote in message
news:eUOFW$5nFHA...@TK2MSFTNGP15.phx.gbl...
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/colorquant.asp
Martyn