![]() So let's start with the function to get these bytes: /// Then you can use Marshal.Copy to get the bytes out without a need to mess around with bare pointers. This is done with the LockBits operation, which gives you access to the underlying memory of the image. So the first thing you have to do is get these bytes. Since this is an 8 bit per pixel image, every colour index value on the image is one byte. Net functions for painting on images can't access these raw index values they can only work with colours. The way to do this is a bit trickier than you might expect. That's why all the colours on the image will be jumbled up.īasically, what you need to do is look at the colours your pixels use, find their closest match on the new palette, and then save the index at which that closest match was found on the new palette into your pixels. So obviously, after your operation, that pixel referring to index 23 will no longer be the red that it had before it'll have whatever colour you replaced index 23 with. So say it has value '23', then that means it uses the colour on index 23 on the palette, and that colour is red.īut you're replacing these colours on the palette. So if you got a red pixel on the image, that's not a pixel with the value "red", it's a pixel with some value from 0 to 255 referring to a colour at that index on the palette. See, the pixels on indexed images do not contain colours. The step you're missing is to match the actual pixels on the image to the new colours. When I compared with the palette file I was give I can see they match perfect.Ĭlearly there is more to it but I can't seem to find anything on the matter.Īpplying a palette is not the same as replacing a palette. So I then took an image that has had the palette applied, I extracted the palette and saved to a file in the JASC-PAL format. Table should be like shades of black/dark blue but they are shades of light brown and some green. I can't upload the image, but to give you an idea, the picture is of a white plate that's on a table. Looks more like someone has chucked pixilated paint lol. When I view the image it just looks totally wrong. Using (FileStream fs = new FileStream(fileName, FileMode.Create, FileAccess.ReadWrite)) Using (MemoryStream memory = new MemoryStream()) ![]() Using (var thumbnail = (fs))įor (int i = 0 i < i++) ![]() Using (FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read)) Using (StreamReader sr = new StreamReader("HH.PAL"))Ĭolor.FromArgb(int.Parse(colourBytes), This is my code, based on my assumption that you just load the file, loop the image's current palette and replace the colours. The palette is stored as a JASC-PAL file. Resizing I got working, but I am having issues with applying the palette. So I have been given a task to re-write a program that converts an image to 3 different sizes, 1 being a 256 colour image with a specific palette applied.
0 Comments
Leave a Reply. |