# Plug-in Request - convert to 256 colors

## Recommended Posts

In MSPaint you have the option to save bmp images in 256 and 16 colors. Is there be a way to make a converter in PdN to reduce the number of colors in a selected area (plug-in maybe)? this would make the image look similar to SearedIce's Cutout Effect http://paintdotnet.12.forumer.com/viewtopic.php?t=1100.

Take responsibility for your own intelligence. 😉 -Rick Brewster

##### Share on other sites

Hm, maybe it would be possible to use GIF dithering engine to do the color downsampling?

Rick will know if it's possible...

##### Share on other sites

```int interval = 64;
int R;
int B;
int G;
int A;
float divR;
float divB;
float divG;
float divA;
ColorBgra fin;

void Render(Surface dst, Surface src, Rectangle rect)
{
for(int y = rect.Top; y < rect.Bottom; y++)
{

for (int x = rect.Left; x < rect.Right; x++)
{
ColorBgra source = src[x, y];
divR = source.R/interval;
divB = source.B/interval;
divG = source.G/interval;
divA = source.A/interval;
R = (int)System.Math.Round(divR);
B = (int)System.Math.Round(divB);
G = (int)System.Math.Round(divG);
A = (int)System.Math.Round(divA);
R = R * interval;
B = B * interval;
G = G * interval;
A = 255; //A * interval;
fin.R = (byte)(R);
fin.B = (byte)(;
fin.G = (byte)(G);
fin.A = (byte)(A);
dst[x, y] =  fin;
}
}
}
```

I love math.

Explanation: a codelab script to make 256 colors without diffusion or dithering.

Also, for 16 colors, change int interval = 64; to int interval = 128; . And yes, this can be simplified. I just don't feel like it.

~~

##### Share on other sites

wow, that was quick!, I'll try it!

EDIT:works great, just what i was looking for

Take responsibility for your own intelligence. 😉 -Rick Brewster

##### Share on other sites

Just making sure everyone knows, this will not save images as 256 color bmp.

~~

##### Share on other sites

what are thoses codes?....never understood that =/

##### Share on other sites

it's for a plugin called CodeLab. if you don't use CodeLab then don't worry about it.

##### Share on other sites

I will be making a formatted plugin, so you know.

_________________

This is my 300th post.

~~

##### Share on other sites

i know it's code lab...the problem is that i dunno use it xD

##### Share on other sites

copy and paste the code into the text box and it will automatically render the picture.

I built my first computer at age 11!

##### Share on other sites

yeah that i know too....what i don REALLY KNOW is to make the codes =/

##### Share on other sites

You're on your own for learning C#. I don't know that much, myself. (I'm just used to javascript.)

~~

##### Share on other sites

• 3 years later...

##### Share on other sites

I have a low color file type plugin that supports saving images to 1bit, 4bit, 8bit and 16bit color depths. viewtopic.php?f=16&t=30638

Also without examining the code posted too much, does it do anything different to the Posterize effect (incuded in Paint.net)? I think setting each Posterize value to 8 (for Red, Green, Blue) will result in 256 possible colors

Don't know what plugin to use? Try looking in the plugin gallery

##### Share on other sites

jxp, the original request predates the postertize plugin, but thank you for your helpful response.

SweterdJ, this is a classic example of why necroposting is against the rules...

Take responsibility for your own intelligence. 😉 -Rick Brewster