Question

I am using PngCs dll to fetch the chunk data for Png image file in asp.net, I am able to do that but now I want to update the chunk data for that PNG.

I used PngWriter but it is creating whole new file without inheriting chunk data.

       PngReader pngr = FileHelper.CreatePngReader(path);
       pngr.GetMetadata().GetTxtForKey(PngChunkITXT.KEY_Title);
       Response.Write(pngr.GetMetadata().GetTxtForKey(PngChunkITXT.KEY_Title));

Below code is for writing new Png Image through PngWriter ,I want embed new itxt chunk while creating new file.

        PngReader pngr = FileHelper.CreatePngReader(origFilename); // or you can use the constructor
        PngWriter pngw = FileHelper.CreatePngWriter(destFilename, pngr.ImgInfo, true); // idem
        Console.WriteLine(pngr.ToString()); // just information
        int chunkBehav = ChunkCopyBehaviour.COPY_ALL_SAFE; // tell to copy all 'safe' chunks
        pngw.CopyChunksFirst(pngr, chunkBehav);          // copy some metadata from reader 

        for (int row = 0; row < pngr.ImgInfo.Rows; row++)
        {
            ImageLine l1 = pngr.ReadRowInt(row); // format: RGBRGB... or RGBARGBA...

            pngw.WriteRow(l1, row);
        }
        pngw.CopyChunksLast(pngr, chunkBehav); // metadata after the image pixels? can happen
        pngw.End(); // dont forget this
        pngr.End();

for further reference click this link

Was it helpful?

Solution 2

the problem has been solved by using CsXMpToolKit.dll ,which is the best option to fetch the metadat from any type of file.

OTHER TIPS

Try this

       PngReader pngr = FileHelper.CreatePngReader(origFilename); 
       PngWriter pngw = FileHelper.CreatePngWriter(destFilename, pngr.ImgInfo, true);                                                     
       pngw.CopyChunksFirst(pngr, ChunkCopyBehaviour.COPY_ALL);
       pngw.GetMetadata().SetText(myKey, myText,false,false); // provide your own data  
       for (int row = 0; row < pngr.ImgInfo.Rows; row++)      {
            ImageLine l1 = pngr.ReadRowInt(row); 
            pngw.WriteRow(l1, row);
       }
       pngw.CopyChunksLast(pngr, ChunkCopyBehaviour.COPY_ALL);
       pngw.End(); // dont forget this
       pngr.End();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top