예제 #1
0
        public static byte[] GetResizedImageBytesGIF89a(Stream stream, Size ts, int quality, out Size sz)
        {
            GifDecoder originalimage = new GifDecoder();

            originalimage.Read(stream);
            sz = originalimage.GetFrameSize();
            return(GetResizedImageBytesGIF89a(originalimage, stream, ts, quality));
        }
예제 #2
0
        public static bool TryGetResizedImageBytesGIF89a(Stream stream, Size ts, int quality, out Size sz, out byte[] bytes)
        {
            bytes = null;
            sz    = default(Size);

            GifDecoder originalimage = new GifDecoder();

            if (!originalimage.TryRead(stream))
            {
                return(false);
            }

            sz    = originalimage.GetFrameSize();
            bytes = GetResizedImageBytesGIF89a(originalimage, stream, ts, quality);
            return(true);
        }
예제 #3
0
        public static byte[] GetThumbnailGIF89a(Stream stream, Size min, Size thumb)
        {
            long       offset  = stream.Position;
            GifDecoder decoder = new GifDecoder();

            decoder.Read(stream);
            Size sz = decoder.GetFrameSize();

            stream.Seek(offset, SeekOrigin.Begin);

            if (min != null && sz.Width < min.Width && sz.Height < min.Height)
            {
                throw new InvalidImageSizeException(
                          string.Empty, sz, min);
            }

            return(GetResizedImageBytesGIF89a(decoder, stream, thumb, s_ImageQuality));
        }
예제 #4
0
        public static byte[] GetResizedImageBytesGIF89a(GifDecoder originalimage, Stream stream, Size ts, int quality)
        {
            Size sz = originalimage.GetFrameSize();

            if (sz.Height > ts.Height || sz.Width > ts.Width)
            {
                MemoryStream ms = new MemoryStream();
                AnimatedGifEncoder.Resize(originalimage, ms, ts.Width, ts.Height, quality);
                ms.Flush();
                byte[]       result       = new byte[ms.Length];
                MemoryStream resultstream = new MemoryStream(result);
                ms.WriteTo(resultstream);
                return(result);
            }
            else
            {
                stream.Seek(0, SeekOrigin.Begin);
                BinaryReader sr = new BinaryReader(stream);
                return(sr.ReadBytes((int)stream.Length));
            }
        }