コード例 #1
0
        public static Frame Create(byte[] buffer, ICONDIRENTRY entry)
        {
            var f = new Frame();

            f.FromFileBuffer(buffer);
            f.iconDir = entry;
            return(f);
        }
コード例 #2
0
        /// <summary>
        /// When creating Icons, this method will generate a valid ICONDIRENTRY
        /// for this frame based on the Bitmap/PNG from which this Frame was built.
        /// </summary>
        public void CreateIconDir()
        {
            iconDir = new ICONDIRENTRY();
            if (type == FrameType.BITMAP)
            {
                // Width, in pixels, of the image
                if (iconImage.Width == 256)
                {
                    iconDir.bWidth = 0;
                }
                else
                {
                    iconDir.bWidth = (byte)iconImage.Width;
                }
                // Height, in pixels, of the image
                if (iconImage.Height == 256)
                {
                    iconDir.bHeight = 0;
                }
                else
                {
                    iconDir.bHeight = (byte)iconImage.Height;
                }
                // Number of colors in image (0 if >=8bpp)
                if (BitsPerPixel == 4)
                {
                    iconDir.bColorCount = 16;
                }
                else
                {
                    iconDir.bColorCount = 0;
                }

                iconDir.bReserved = 0;                    // Reserved ( must be 0)
                iconDir.wPlanes   = 1;                    // Color Planes
                iconDir.wBitCount = (ushort)BitsPerPixel; // Bits per pixel

                iconDir.dwBytesInRes = iconImage.SizeOf;
            }
            else
            {
                // Width, in pixels, of the image
                if (Width == 256)
                {
                    iconDir.bWidth = 0;
                }
                else
                {
                    iconDir.bWidth = (byte)Width;
                }
                // Height, in pixels, of the image
                if (Height == 256)
                {
                    iconDir.bHeight = 0;
                }
                else
                {
                    iconDir.bHeight = (byte)Height;
                }
                // Number of colors in image (0 if >=8bpp)
                if (BitsPerPixel == 4)
                {
                    iconDir.bColorCount = 16;
                }
                else
                {
                    iconDir.bColorCount = 0;
                }

                iconDir.bReserved = 0;                    // Reserved ( must be 0)
                iconDir.wPlanes   = 1;                    // Color Planes
                iconDir.wBitCount = (ushort)BitsPerPixel; // Bits per pixel


                iconDir.dwBytesInRes = (uint)pngBuffer.Length;
            }
        }