Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Deleting the Palette Chunk from png stream

Deleting the Palette Chunk from png stream

Scheduled Pinned Locked Moved C#
csharpquestion
7 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Shailesh H
    wrote on last edited by
    #1

    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?

    L B 2 Replies Last reply
    0
    • S Shailesh H

      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?

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      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).

      S 1 Reply Last reply
      0
      • L Lost User

        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).

        S Offline
        S Offline
        Shailesh H
        wrote on last edited by
        #3

        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.

        L 1 Reply Last reply
        0
        • S Shailesh H

          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?

          B Offline
          B Offline
          BobJanova
          wrote on last edited by
          #4

          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.

          S 1 Reply Last reply
          0
          • B BobJanova

            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.

            S Offline
            S Offline
            Shailesh H
            wrote on last edited by
            #5

            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

            B 1 Reply Last reply
            0
            • S Shailesh H

              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.

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              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).

              1 Reply Last reply
              0
              • S Shailesh H

                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

                B Offline
                B Offline
                BobJanova
                wrote on last edited by
                #7

                Read the file using file reading tools (e.g. FileStream), find the PLTE chunk and rewrite the file not including it. This will require you to understand the PNG file format so you can recognise the part you want to process differently.

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups