Saving an image with "Web Safe" Colors
page 1 of 1
Published: 05 Dec 2003
Unedited - Community Contributed
Abstract
In this example we set the GIF to use a standard "web safe" non-dithering palette, using GDI+ and System.Drawing.
by Chris Garrett
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 6703/ 13

Saving an image with "Web Safe" Colors
Saving an image with "Web Safe" Colours
by Chris Garrett

Almost as soon as I posted my previous article on setting the palette and background transparency of a GIF I got emails from people asking to fill in the missing information - namely how to set the palette of the resulting image to something useful.

In this example we set the GIF to use a standard "web safe" non-dithering palette.

Before

After


View Source
- /chrisg/tools/view-websafegif.vb.aspx
- /chrisg/tools/view-websafegif.aspx.aspx

 

The code begins by loading in a bitmap that contains some reference pictures so we can compare the final result.

We then create a SortedList of web safe colours with three nested for .. next loops, using the fact that web safe colours are made up of a fixed set of values.

This fact also comes in handy with selecting the closest colour match, we simply select the closest value for each of the red, green and blue values.

 

Download
- /chrisg/tools/download.asp?file=websafegif.aspx
- /chrisg/tools/download.asp?file=websafegif.vb



User Comments

No comments posted yet.

Product Spotlight
Product Spotlight 





Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-04-19 6:22:31 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search