[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.drawing

how to make a colored gif a black & white gif

M. Posseth

12/1/2004 4:13:00 PM

hello ,,,

my webserver uses this piece of code to retrieve a gif picture

Dim g As System.Drawing.Image = System.Drawing.Image.FromFile(strSource)
Response.Clear()
g.Save(Response.OutputStream, ImageFormat.Gif)
g.Dispose()

where "strSource" is ofcourse a var holding the location of the gif image

this works fine ,,,, however does someone knows a simple way of converting
these colored gifs to black and white pictures ?? ( this are line drawing
schema`s , the background is already white but the lines in it could be
colored in red blue , green etc etc etc they should all become black )


in VB6 i could just loop pixel by pixel through a image control and replace
all non wanted colors is something like that also possible with VB.NET ????

thank you ,,,

M. Posseth [MCP]


2 Answers

Robby

12/2/2004 11:08:00 AM

0

The only way I know how to do this is with a pixel-by-pixel RGB color
conversion to grey scale color. The back-grey-white in RGB is when all
parts are equal. {0, 0, 0) is black, {n, n, n} is grey for n in [1, 254] and
{255, 255, 255} is white. You can get the grey scale of a RGB color by
taking the average of the sum of the parts and using that as your n for
grey. For example a yellow of {255, 255, 0} will have an n = (255 + 255 +
0)/3 = 170 so its grey scale will be {170, 170, 170}.

You can pass your Image object to the constructor of the Bitmap object and
then use the GetPixel method to get the color of the pixel. You would then
get its grey scale, create a Color object in that color and write a pixel
back to the Bitmap object at the same position using the SetPixel method.
When you finished the conversion you could then cast the Bitmap object to an
Image object. Now you can continue your code with your grey scale image.

Does anyone know of a different way? Some perhaps a little faster or a some
..Net componet that does this for you?

Hope this helps

Robby


"M. Posseth" <M. Posseth @discussions.microsoft.com> wrote in message
news:782FEC5D-78D2-4C9A-B283-200093A0FC4B@microsoft.com...
> hello ,,,
>
> my webserver uses this piece of code to retrieve a gif picture
>
> Dim g As System.Drawing.Image = System.Drawing.Image.FromFile(strSource)
> Response.Clear()
> g.Save(Response.OutputStream, ImageFormat.Gif)
> g.Dispose()
>
> where "strSource" is ofcourse a var holding the location of the gif image
>
> this works fine ,,,, however does someone knows a simple way of converting
> these colored gifs to black and white pictures ?? ( this are line
> drawing
> schema`s , the background is already white but the lines in it could be
> colored in red blue , green etc etc etc they should all become black )
>
>
> in VB6 i could just loop pixel by pixel through a image control and
> replace
> all non wanted colors is something like that also possible with VB.NET
> ????
>
> thank you ,,,
>
> M. Posseth [MCP]
>
>


Bob Powell

12/2/2004 5:12:00 PM

0

There are two articles in the GDI+ FAQ that can be amalgamated to perform
this function.

First, the conversion of an image to a monochrome is explained, Secondly a
technique for saving a GIF with a custom palette is detailed.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tips...

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/f...

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.





"M. Posseth" <M. Posseth @discussions.microsoft.com> wrote in message
news:782FEC5D-78D2-4C9A-B283-200093A0FC4B@microsoft.com...
> hello ,,,
>
> my webserver uses this piece of code to retrieve a gif picture
>
> Dim g As System.Drawing.Image = System.Drawing.Image.FromFile(strSource)
> Response.Clear()
> g.Save(Response.OutputStream, ImageFormat.Gif)
> g.Dispose()
>
> where "strSource" is ofcourse a var holding the location of the gif image
>
> this works fine ,,,, however does someone knows a simple way of converting
> these colored gifs to black and white pictures ?? ( this are line
drawing
> schema`s , the background is already white but the lines in it could be
> colored in red blue , green etc etc etc they should all become black )
>
>
> in VB6 i could just loop pixel by pixel through a image control and
replace
> all non wanted colors is something like that also possible with VB.NET
????
>
> thank you ,,,
>
> M. Posseth [MCP]
>
>