コード例 #1
0
        private void uiChunkList_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            PngDataChunk currentChunk = uiChunkList.SelectedItem as PngDataChunk;

            if (currentChunk != null)
            {
                switch (currentChunk.Type.ToString())
                {
                case "IHDR":
                    CtrlShowIHDR headerControl = new CtrlShowIHDR();
                    headerControl.HeaderData = currentChunk.ParsedData as ParsedIHDR;
                    headerControl.UpdateView();
                    tabChunkContents.Content = headerControl;
                    break;

                case "gAMA":
                    CtrlShowGAMA gammaControl = new CtrlShowGAMA();
                    gammaControl.GammaData = currentChunk.ParsedData as ParsedGAMA;
                    gammaControl.UpdateView();
                    tabChunkContents.Content = gammaControl;
                    break;

                case "tEXt":
                    CtrlShowTEXT textControl = new CtrlShowTEXT();
                    textControl.DataContext  = currentChunk.ParsedData as ParsedTEXT;
                    tabChunkContents.Content = textControl;
                    break;

                case "iTXt":
                    CtrlShowITXT itextControl = new CtrlShowITXT();
                    itextControl.DataContext = currentChunk.ParsedData as ParsedITXT;
                    tabChunkContents.Content = itextControl;
                    break;

                case "tIME":
                    CtrlShowTIME timeControl = new CtrlShowTIME();
                    timeControl.DataContext  = currentChunk.ParsedData as ParsedTIME;
                    tabChunkContents.Content = timeControl;
                    break;

                default:
                    tabChunkContents.Content = new TextBlock {
                        Text = "Data cannot be displayed."
                    };
                    break;
                }

                tbRawHex.Text   = SplitStringIntoLines(BitConverter.ToString(currentChunk.GetBytes()).Replace("-", " "), 24);
                tbRawAscii.Text = SplitStringIntoLines(ByteUtils.ParseAscii(currentChunk.GetBytes()), 8);

                btnDelete.IsEnabled = true;
            }
            else
            {
                btnDelete.IsEnabled = false;
            }
        }
コード例 #2
0
        /// <summary>
        /// Returns whether this PngDataChunk is the same as another PngDataChunk, based on the CRC checksum.
        /// </summary>
        /// <param name="obj">object</param>
        /// <returns>true if this == object, false otherwise</returns>
        public override bool Equals(object obj)
        {
            PngDataChunk chunk = obj as PngDataChunk;

            if (chunk == null)
            {
                return(false);
            }
            return(CalculateCrc() == chunk.CalculateCrc());
        }
コード例 #3
0
ファイル: ImageData.cs プロジェクト: K2705/PngMeta
        public static PngDataChunk NewItxtChunk(string keyword, bool compressed, string language, string translatedKeyword, string text)
        {
            ParsedITXT   data  = new ParsedITXT(keyword, compressed, language, translatedKeyword, text);
            PngDataChunk chunk = new PngDataChunk(new ChunkType("iTXt"));

            chunk.ParsedData = data;
            chunk.UpdateData();
            chunk.UpdateLength();
            chunk.UpdateLength();
            return(chunk);
        }
コード例 #4
0
ファイル: ImageData.cs プロジェクト: K2705/PngMeta
        public static PngDataChunk NewTextChunk(string keyword, string text)
        {
            ParsedTEXT   data  = new ParsedTEXT(keyword, text);
            PngDataChunk chunk = new PngDataChunk(new ChunkType("tEXt"));

            chunk.ParsedData = data;
            chunk.UpdateData();
            chunk.UpdateLength();
            chunk.UpdateCrc();
            return(chunk);
        }
コード例 #5
0
        private void btnDelete_Click(object sender, RoutedEventArgs e)
        {
            PngDataChunk selectedChunk = uiChunkList.SelectedItem as PngDataChunk;

            if (selectedChunk != null && selectedChunk.Type.Ancillary)
            {
                MessageBoxResult result = MessageBox.Show("Are you sure you want to permanently delete chunk " + selectedChunk.TypeString() + "?", "", MessageBoxButton.YesNo);
                if (result == MessageBoxResult.Yes)
                {
                    imageWrapper.FileChunks.Remove(selectedChunk);
                    uiChunkList.Items.Refresh();
                }
            }
            else
            {
                MessageBox.Show("Cannot remove " + selectedChunk.TypeString() + ", as it is a critical chunk.");
            }
        }
コード例 #6
0
ファイル: ImageData.cs プロジェクト: K2705/PngMeta
        public static List <PngDataChunk> GetChunks(byte[] imageBytes)
        {
            // Check for the eight-byte PNG signature
            byte[] pngHeader = { 137, 80, 78, 71, 13, 10, 26, 10, };
            for (int i = 0; i < 8; i++)
            {
                if (pngHeader[i] != imageBytes[i])
                {
                    throw new ArgumentException("No PNG signature found");
                }
            }

            List <PngDataChunk> chunks = new List <PngDataChunk>();
            int k = 8;

            while (true)
            {
                // get the data
                UInt32 chunkLength = ByteUtils.ToUInt32(imageBytes, k);
                k += 4;
                ChunkType chunkType = new ChunkType(imageBytes, k);
                k += 4;
                byte[] chunkData = new byte[chunkLength];
                for (int i = 0; i < chunkLength; i++, k++)
                {
                    chunkData[i] = imageBytes[k];
                }
                UInt32 chunkCRC = ByteUtils.ToUInt32(imageBytes, k);
                k += 4;

                // create chunk from data and add it to list
                PngDataChunk dataChunk = new PngDataChunk(chunkLength, chunkType, chunkData, chunkCRC);
                chunks.Add(dataChunk);

                // stop once we hit the IEND
                if (chunkType.ToString() == "IEND")
                {
                    break;
                }
                // TODO: proper error handling if IEND is never found
            }

            return(chunks);
        }