Deleting the Palette Chunk from png stream
-
I am working on a Png encoder software . This software has a requirement that it should generate a png file without the PLTE(palette) chunk , so I want to programmatically delete the "palette chunk" using C#.Net. Anybody out here knows how it can be done using the dotnet framework?
-
I am working on a Png encoder software . This software has a requirement that it should generate a png file without the PLTE(palette) chunk , so I want to programmatically delete the "palette chunk" using C#.Net. Anybody out here knows how it can be done using the dotnet framework?
-
Why don't you just not encode it as paletted in the first place? Anyway if you're going to forcefully remove the PLTE chunk (which is pretty easy), beware that that makes the PNG invalid (indexed PNG's need a PLTE chunk).
Yes right ... Deleting palette chunk will make the PNG invalid i know that .. but thats the requirement. You said that the deleting palette chunk is easy. How do i implement that in C#.Net?? Kindly reply.
-
I am working on a Png encoder software . This software has a requirement that it should generate a png file without the PLTE(palette) chunk , so I want to programmatically delete the "palette chunk" using C#.Net. Anybody out here knows how it can be done using the dotnet framework?
-
You'll have to work with the file format directly. The .Net API won't let you create an indexed image without the colour table, because it's invalid.
I have created a .png file from say a bmp using the Image.Save() call. Now I want to delete the PLTE chunk from the .png file created , how do I do it?? Best Regards
-
Yes right ... Deleting palette chunk will make the PNG invalid i know that .. but thats the requirement. You said that the deleting palette chunk is easy. How do i implement that in C#.Net?? Kindly reply.
Ok that's odd, but ok. This is what I would do. Read the file back with a BinaryReader. Beware that integers in PNG are stored big-endian, so if you need their integer value you have to byte-reverse it (there is of course no good reason to reverse the FourCC's, just reverse the constants you test them against). Write all chunks to an other stream unless the FourCC of the chunk is PLTE (FourCC's can not be read as strings because they are not strings in the way BinaryReader wants them, just read an int32 and test against 0x45544C50 (ETLP in ASCII) - the other FourCC's are not relevant, just write anything "unknown" to the destination stream).
-
I have created a .png file from say a bmp using the Image.Save() call. Now I want to delete the PLTE chunk from the .png file created , how do I do it?? Best Regards