Пример #1
0
        public virtual Bitmap GetImage()
        {
            var data     = SwfZip.DecompressZlib(ZlibBitmapData);
            var bmp      = new Bitmap(BitmapWidth, BitmapHeight);
            var lineSize = BitmapWidth;

            for (var y = 0; y < bmp.Height; y++)
            {
                for (var x = 0; x < bmp.Width; x++)
                {
                    var ind   = (y * lineSize + x) * 4;
                    var alpha = data[ind];
                    if (alpha <= 0)
                    {
                        alpha = 1;
                    }
                    var red   = data[ind + 1] * 255 / alpha;
                    var green = data[ind + 2] * 255 / alpha;
                    var blue  = data[ind + 3] * 255 / alpha;
                    var clr   = Color.FromArgb(alpha, red, green, blue);
                    bmp.SetPixel(x, y, clr);
                }
            }
            return(bmp);
        }
Пример #2
0
        protected static SwfStreamReader GetSwfStreamReader(SwfFileInfo info, Stream stream)
        {
            if (info.Format == SwfFormat.Unknown)
            {
                throw new NotSupportedException("Illegal file format");
            }
            if (info.Format == SwfFormat.FWS)
            {
                return(new SwfStreamReader(stream));
            }
            var mem = new MemoryStream();

            SwfZip.Decompress(stream, mem, info.Format);
            return(new SwfStreamReader(mem));
        }
Пример #3
0
        private static Stream DecompressIfNeeded(SwfFileInfo info, Stream stream)
        {
            if (info.Format == SwfFormat.Unknown)
            {
                throw new NotSupportedException("Illegal file format");
            }
            if (info.Format == SwfFormat.FWS)
            {
                return(stream);
            }

            var mem = new MemoryStream();

            SwfZip.Decompress(stream, mem, info.Format);
            return(mem);
        }
Пример #4
0
        protected static Bitmap SetAlphas(Bitmap bmp, byte[] compressedAlpha)
        {
            var alpha = SwfZip.Decompress(compressedAlpha, SwfFormat.CWS);
            var index = 0;
            var res   = new Bitmap(bmp.Width, bmp.Height, PixelFormat.Format32bppArgb);

            for (var y = 0; y < bmp.Height; y++)
            {
                for (var x = 0; x < bmp.Width; x++)
                {
                    var clr = bmp.GetPixel(x, y);
                    clr = Color.FromArgb(alpha[index], clr);
                    res.SetPixel(x, y, clr);
                    index++;
                }
            }
            return(res);
        }
Пример #5
0
        public void SetImage(Bitmap bmp)
        {
            BitmapWidth  = (ushort)bmp.Width;
            BitmapHeight = (ushort)bmp.Height;
            BitmapFormat = 5;
            var lineSize = BitmapWidth;
            var data     = new byte[lineSize * BitmapHeight * 4];

            for (var y = 0; y < bmp.Height; y++)
            {
                for (var x = 0; x < bmp.Width; x++)
                {
                    var ind = (y * lineSize + x) * 4;
                    var clr = bmp.GetPixel(x, y);
                    data[ind]     = clr.A;
                    data[ind + 1] = (byte)(clr.R * clr.A / 255);
                    data[ind + 2] = (byte)(clr.G * clr.A / 255);
                    data[ind + 3] = (byte)(clr.B * clr.A / 255);
                }
            }
            ZlibBitmapData = SwfZip.CompressZlib(data);
        }