Robby
12/2/2004 11:08:00 AM
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]
>
>