Dispose() public method

Frees and releases all resources allocated by this JpegImage
public Dispose ( ) : void
return void
コード例 #1
0
 public override Image Load(Stream s)
 {
     BitMiracle.LibJpeg.JpegImage j = new BitMiracle.LibJpeg.JpegImage(s);
     Image i = (Image)j.ToBitmap();
     j.Dispose();
     System.GC.Collect();
     return i;
 }
コード例 #2
0
ファイル: JpegSupport.cs プロジェクト: zer09/Cosmos
        public override Image Load(Stream s)
        {
            BitMiracle.LibJpeg.JpegImage j = new BitMiracle.LibJpeg.JpegImage(s);
            Image i = (Image)j.ToBitmap();

            j.Dispose();
            System.GC.Collect();
            return(i);
        }
コード例 #3
0
ファイル: JpegSupport.cs プロジェクト: zer09/Cosmos
        public override void Save(Image i, Stream dest)
        {
            BitMiracle.LibJpeg.JpegImage j = BitMiracle.LibJpeg.JpegImage.FromBitmap((System.Drawing.Bitmap)i);
            CompressionParameters        c = new CompressionParameters();

            c.Quality           = 100;
            c.SimpleProgressive = false;
            j.WriteJpeg(dest, c);
            j.Dispose();
            System.GC.Collect();
        }
コード例 #4
0
        /// <summary>
        /// Decodes the image from the specified stream and sets
        /// the data to image.
        /// </summary>
        /// <param name="image">The image, where the data should be set to.
        /// Cannot be null (Nothing in Visual Basic).</param>
        /// <param name="stream">The stream, where the image should be
        /// decoded from. Cannot be null (Nothing in Visual Basic).</param>
        /// <exception cref="System.ArgumentNullException">
        /// 	<para><paramref name="image"/> is null (Nothing in Visual Basic).</para>
        /// 	<para>- or -</para>
        /// 	<para><paramref name="stream"/> is null (Nothing in Visual Basic).</para>
        /// </exception>
        public void Decode(Image image, Stream stream)
        {
            Guard.NotNull(image, "image");
            Guard.NotNull(stream, "stream");
            JpegImage jpg = new JpegImage(stream);

            int pixelWidth = jpg.Width;
            int pixelHeight = jpg.Height;

            float[] pixels = new float[pixelWidth * pixelHeight * 4];

            if (jpg.Colorspace == Colorspace.RGB && jpg.BitsPerComponent == 8)
            {
                Parallel.For(
                    0,
                    pixelHeight,
                    y =>
                        {
                            SampleRow row = jpg.GetRow(y);

                            for (int x = 0; x < pixelWidth; x++)
                            {
                                Sample sample = row.GetAt(x);

                                int offset = ((y * pixelWidth) + x) * 4;

                                pixels[offset + 0] = sample[0] / 255f;
                                pixels[offset + 1] = sample[1] / 255f;
                                pixels[offset + 2] = sample[2] / 255f;
                                pixels[offset + 3] = 1;
                            }
                        });
            }
            else if (jpg.Colorspace == Colorspace.Grayscale && jpg.BitsPerComponent == 8)
            {
                Parallel.For(
                    0,
                    pixelHeight,
                    y =>
                    {
                        SampleRow row = jpg.GetRow(y);

                        for (int x = 0; x < pixelWidth; x++)
                        {
                            Sample sample = row.GetAt(x);

                            int offset = ((y * pixelWidth) + x) * 4;

                            pixels[offset + 0] = sample[0] / 255f;
                            pixels[offset + 1] = sample[0] / 255f;
                            pixels[offset + 2] = sample[0] / 255f;
                            pixels[offset + 3] = 1;
                        }
                    });
            }
            else
            {
                throw new NotSupportedException("JpegDecoder only supports RGB and Grayscale color spaces.");
            }

            image.SetPixels(pixelWidth, pixelHeight, pixels);

            jpg.Dispose();
        }