c# - Can't set palette in bitmap -


i have been writing pcx decoder and, far, pcx image parses fine, can't work out how set palette of bitmap.

i have created bitmap so:

bitmap bmp = new bitmap(width,                         height,                         stride2,                         system.drawing.imaging.pixelformat.format8bppindexed,                         pixels); 

but can't seem set palette using following method:

for (int = 0; < 256; += 3) {     color b = new color();     b = color.fromargb(palette[i], palette[i + 1], palette[i + 2]);     bmp.palette.entries.setvalue(b, i); } 

in example, have read through each byte in palette of pcx file , stored them in palette[]. there, have used set entries in palette of bitmap. how set colours?

this had me confused too. seems bitmap.palette returns clone of bitmap's palette. once you've modified copy, need reset bitmap's pallete using bitmap.palette = palette, e.g.

colorpalette palette = bitmap.palette; color entries = palette.entries; .... entries[i] = new color(...); .... bitmap.palette = palette; // crucial statement 

see http://www.charlespetzold.com/pwcs/palettechange.html


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -