public void SaveAdd(Image image, EncoderParameters encoderParams)
        {
            Status st;

            IntPtr nativeEncoderParams = encoderParams.ToNativePtr();

            st = GDIPlus.GdipSaveAddImage(nativeObject, image.NativeObject, nativeEncoderParams);
            Marshal.FreeHGlobal(nativeEncoderParams);
            GDIPlus.CheckStatus(st);
        }
Exemple #2
0
        public void Save(string filename, ImageCodecInfo encoder, EncoderParameters encoderParams)
        {
            if (filename == null)
            {
                throw new ArgumentNullException("filename");
            }
            if (encoder == null)
            {
                throw new ArgumentNullException("encoder");
            }

            IntSecurity.DemandWriteFileIO(filename);

            Status st;
            Guid   guid = encoder.Clsid;

            if (encoderParams != null)
            {
                rawData = null;
                IntPtr nativeEncoderParams = encoderParams.ToNativePtr();
                st = GDIPlus.GdipSaveImageToFile(nativeObject, filename, ref guid, nativeEncoderParams);
                Marshal.FreeHGlobal(nativeEncoderParams);
                GDIPlus.CheckStatus(st);
            }
            try
            {
                bool saved = false;
                if (rawData != null)
                {
                    if (encoder.Clsid == guid)
                    {
                        using (FileStream fs = File.OpenWrite(filename))
                        {
                            fs.Write(rawData, 0, rawData.Length);
                            saved = true;
                        }
                    }
                }

                if (!saved)
                {
                    st = GDIPlus.GdipSaveImageToFile(nativeObject, filename, ref guid, IntPtr.Zero);
                    GDIPlus.CheckStatus(st);
                }
            }
            finally
            {
                GC.Collect();
                GC.WaitForFullGCComplete();
            }
        }
        public void Save(string filename, ImageCodecInfo encoder, EncoderParameters encoderParams)
        {
            Status st;
            Guid   guid = encoder.Clsid;

            if (encoderParams == null)
            {
                st = GDIPlus.GdipSaveImageToFile(nativeObject, filename, ref guid, IntPtr.Zero);
            }
            else
            {
                IntPtr nativeEncoderParams = encoderParams.ToNativePtr();
                st = GDIPlus.GdipSaveImageToFile(nativeObject, filename, ref guid, nativeEncoderParams);
                Marshal.FreeHGlobal(nativeEncoderParams);
            }

            GDIPlus.CheckStatus(st);
        }
        public void Save(Stream stream, ImageCodecInfo encoder, EncoderParameters encoderParams)
        {
            Status st;
            IntPtr nativeEncoderParams;
            Guid   guid = encoder.Clsid;

            if (encoderParams == null)
            {
                nativeEncoderParams = IntPtr.Zero;
            }
            else
            {
                nativeEncoderParams = encoderParams.ToNativePtr();
            }

            try
            {
                if (GDIPlus.RunningOnUnix())
                {
                    GDIPlus.GdiPlusStreamHelper sh = new GDIPlus.GdiPlusStreamHelper(stream, false);
                    st = GDIPlus.GdipSaveImageToDelegate_linux(nativeObject, sh.GetBytesDelegate, sh.PutBytesDelegate,
                                                               sh.SeekDelegate, sh.CloseDelegate, sh.SizeDelegate, ref guid, nativeEncoderParams);
                }
                else
                {
                    st = GDIPlus.GdipSaveImageToStream(new HandleRef(this, nativeObject),
                                                       new ComIStreamWrapper(stream), ref guid, new HandleRef(encoderParams, nativeEncoderParams));
                }
            }
            finally
            {
                if (nativeEncoderParams != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(nativeEncoderParams);
                }
            }

            GDIPlus.CheckStatus(st);
        }