public Metafile(IntPtr referenceHdc, EmfType emfType, string description)
 {
     System.Drawing.IntSecurity.ObjectFromWin32Handle.Demand();
     IntPtr zero = IntPtr.Zero;
     int status = SafeNativeMethods.Gdip.GdipRecordMetafile(new HandleRef(null, referenceHdc), (int) emfType, System.Drawing.NativeMethods.NullHandleRef, 7, description, out zero);
     if (status != 0)
     {
         throw SafeNativeMethods.Gdip.StatusException(status);
     }
     base.SetNativeImage(zero);
 }
		private void CreateInternalMetafile(EmfType type)
		{
			//Create a temporary bitmap to get an HDC
			Graphics graphics = Component.Instance.CreateGraphics();
			IntPtr hDC = graphics.GetHdc();

			//Create metafile based on type and get graphics handle
			mMetafile = new System.Drawing.Imaging.Metafile(hDC, type);
			graphics.ReleaseHdc(hDC);

			graphics.Dispose();
		}
        public static Metafile CreateMetafile(
            this BitmapSource bitmap, 
            double horizontalScale = 1.0,
            double verticalScale = 1.0,
            EmfType emf = EmfType.EmfOnly,
            SmoothingMode smoothingMode = SmoothingMode.HighQuality,
            InterpolationMode interpolationMode = InterpolationMode.HighQualityBicubic,
            PixelOffsetMode pixelOffsetMode = PixelOffsetMode.HighQuality,
            CompositingQuality compositingQuality = CompositingQuality.HighQuality)
        {
            var mf = (Metafile)null;

            using (System.Drawing.Graphics cx = System.Drawing.Graphics.FromHwndInternal(IntPtr.Zero))
            {
                mf = new Metafile(new MemoryStream(), cx.GetHdc(), emf);

                using (var g = System.Drawing.Graphics.FromImage(mf))
                {
                    var img = bitmap.ToBitmap();

                    g.SmoothingMode = smoothingMode;
                    g.InterpolationMode = interpolationMode;
                    g.PixelOffsetMode = pixelOffsetMode;
                    g.CompositingQuality = compositingQuality;

                    var rect =
                        new System.Drawing.RectangleF(
                            0,
                            0,
                            img.PhysicalDimension.Width * (float)horizontalScale,
                            img.PhysicalDimension.Height * (float)verticalScale);

                    g.DrawImage(img, rect);
                }
            }

            return mf;
        }
Exemple #4
0
 public Metafile(Stream stream, IntPtr referenceHdc, RectangleF frameRect, MetafileFrameUnit frameUnit,
                 EmfType type) : this(stream, referenceHdc, frameRect, frameUnit, type, null)
 {
 }
Exemple #5
0
		public Metafile (string fileName, IntPtr referenceHdc, RectangleF frameRect, MetafileFrameUnit frameUnit,
			EmfType type) : this (fileName, referenceHdc, frameRect, frameUnit, type, null)
		{
		}
	public Metafile(Stream stream, IntPtr referenceHdc, EmfType type)
			: this(stream, referenceHdc, type, null) {}
Exemple #7
0
		public Metafile (IntPtr referenceHdc, EmfType emfType) :
			this (referenceHdc, new RectangleF (), MetafileFrameUnit.GdiCompatible, emfType, null)
		{
		}
        public Metafile(Stream stream, IntPtr referenceHdc, Rectangle frameRect, MetafileFrameUnit frameUnit,
                        EmfType type, string description)
        {
            IntSecurity.ObjectFromWin32Handle.Demand();

            IntPtr metafile = IntPtr.Zero;

            int status;

            if (frameRect.IsEmpty) {
                status = SafeNativeMethods.Gdip.GdipRecordMetafileStream(new GPStream(stream), 
                                                          new HandleRef(null, referenceHdc), 
                                                          unchecked((int)type),
                                                          NativeMethods.NullHandleRef, 
                                                          unchecked((int)frameUnit), 
                                                          description, 
                                                          out metafile);
            }
            else {
                GPRECT gprect = new GPRECT(frameRect);
                status = SafeNativeMethods.Gdip.GdipRecordMetafileStreamI(new GPStream(stream), 
                                                           new HandleRef(null, referenceHdc), 
                                                           unchecked((int)type),
                                                           ref gprect, 
                                                           unchecked((int)frameUnit), 
                                                           description, 
                                                           out metafile);
            }

            if (status != SafeNativeMethods.Gdip.Ok)
                throw SafeNativeMethods.Gdip.StatusException(status);

            SetNativeImage(metafile);
        }
Exemple #9
0
		internal static extern Status GdipRecordMetafileStreamI ([MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(ComIStreamMarshaler))] IStream stream, IntPtr hdc, 
			EmfType type, ref Rectangle frameRect, MetafileFrameUnit frameUnit, [MarshalAs (UnmanagedType.LPWStr)] string description, out IntPtr metafile);
	public Metafile(System.IO.Stream stream, System.IntPtr referenceHdc, EmfType type) {}
	public Metafile(System.IO.Stream stream, System.IntPtr referenceHdc, EmfType type, string description) {}
Exemple #12
0
 public Metafile(Stream stream, IntPtr referenceHdc,
                 EmfType type, string description)
 {
     // TODO
 }
Exemple #13
0
 public Metafile(Stream stream, IntPtr referenceHdc,
                 Rectangle frameRect, MetafileFrameUnit frameUnit,
                 EmfType type, string description)
 {
     // TODO
 }
Exemple #14
0
 public Metafile(string fileName, IntPtr referenceHdc,
                 EmfType type, string description)
 {
     // TODO
 }
Exemple #15
0
 public Metafile(IntPtr referenceHtc, EmfType emfType)
 {
     throw new NotImplementedException();
 }
Exemple #16
0
 public Metafile(string fileName, IntPtr referenceHdc, RectangleF frameRect, MetafileFrameUnit frameUnit, EmfType type,
                 string description)
 {
     throw new NotImplementedException();
 }
Exemple #17
0
 public Metafile(IntPtr referenceHdc, EmfType emfType) :
     this(referenceHdc, new RectangleF(), MetafileFrameUnit.GdiCompatible, emfType, null)
 {
 }
	public Metafile(System.IO.Stream stream, System.IntPtr referenceHdc, System.Drawing.Rectangle frameRect, MetafileFrameUnit frameUnit, EmfType type, string description) {}
        public Metafile(string fileName, IntPtr referenceHdc, RectangleF frameRect,
                        MetafileFrameUnit frameUnit, EmfType type, String description)
        {
            IntSecurity.DemandReadFileIO(fileName);
            IntSecurity.ObjectFromWin32Handle.Demand();

            IntPtr metafile = IntPtr.Zero;

            GPRECTF rectf = new GPRECTF(frameRect);
            int status = SafeNativeMethods.Gdip.GdipRecordMetafileFileName(fileName, 
                                                            new HandleRef(null, referenceHdc), 
                                                            unchecked((int)type), 
                                                            ref rectf,
                                                            unchecked((int)frameUnit), 
                                                            description, 
                                                            out metafile);

            if (status != SafeNativeMethods.Gdip.Ok)
                throw SafeNativeMethods.Gdip.StatusException(status);

            SetNativeImage(metafile);
        }
	public Metafile(System.IntPtr referenceHdc, EmfType emfType) {}
Exemple #21
0
 public Metafile(IntPtr referenceHdc, EmfType emfType) :
     this(referenceHdc, emfType, null)
 {
 }
Exemple #22
0
        public Metafile(IntPtr referenceHdc, Rectangle frameRect, MetafileFrameUnit frameUnit, EmfType type,
                        string desc)
        {
            int status = SafeNativeMethods.Gdip.GdipRecordMetafileI(referenceHdc, type, ref frameRect, frameUnit,
                                                                    desc, out nativeImage);

            SafeNativeMethods.Gdip.CheckStatus(status);
        }
Exemple #23
0
		private void RecordFileName (IntPtr hdc, EmfType type, MetafileFrameUnit unit)
		{
			string filename = String.Format ("test-{0}-{1}.emf", type, unit);
			IntPtr metafile;
			RectangleF rect = new RectangleF (10, 20, 100, 200);
			Status status = GDIPlus.GdipRecordMetafileFileName (filename, hdc, type, ref rect, unit, filename, out metafile);
			if (metafile != IntPtr.Zero)
				GDIPlus.GdipDisposeImage (metafile);
			if (status == Status.Ok)
				File.Delete (filename);
			Assert.AreEqual (Status.Ok, status, filename);
		}
Exemple #24
0
 public Metafile(Stream stream, IntPtr referenceHdc, EmfType type, string description) :
     this(stream, referenceHdc, default(RectangleF), MetafileFrameUnit.GdiCompatible, type, description)
 {
 }
	public Metafile(String fileName, IntPtr referenceHdc,
					EmfType type, String description)
			{
				// TODO
			}
        /// <summary>
        /// Initializes a new instance of the <see cref='Metafile'/> class from the specified device context, bounded
        /// by the specified rectangle.
        /// </summary>
        public Metafile(IntPtr referenceHdc, Rectangle frameRect, MetafileFrameUnit frameUnit, EmfType type, string desc)
        {
            IntPtr metafile = IntPtr.Zero;

            if (frameRect.IsEmpty)
            {
                Gdip.CheckStatus(Gdip.GdipRecordMetafile(
                                     new HandleRef(null, referenceHdc),
                                     type,
                                     NativeMethods.NullHandleRef,
                                     MetafileFrameUnit.GdiCompatible,
                                     desc,
                                     out metafile));
            }
            else
            {
                Gdip.CheckStatus(Gdip.GdipRecordMetafileI(
                                     new HandleRef(null, referenceHdc),
                                     type,
                                     ref frameRect,
                                     frameUnit,
                                     desc,
                                     out metafile));
            }

            SetNativeImage(metafile);
        }
Exemple #27
0
 public Metafile(Stream stream, IntPtr referenceHdc, RectangleF frameRect, MetafileFrameUnit frameUnit, EmfType type)
 {
     throw new NotImplementedException();
 }
        /// <summary>
        /// Initializes a new instance of the <see cref='Metafile'/> class with the specified filename.
        /// </summary>
        public Metafile(string fileName, IntPtr referenceHdc, Rectangle frameRect, MetafileFrameUnit frameUnit, EmfType type, string description)
        {
            // Called in order to emulate exception behavior from netfx related to invalid file paths.
            Path.GetFullPath(fileName);

            IntPtr metafile = IntPtr.Zero;

            if (frameRect.IsEmpty)
            {
                Gdip.CheckStatus(Gdip.GdipRecordMetafileFileName(
                                     fileName,
                                     new HandleRef(null, referenceHdc),
                                     type,
                                     NativeMethods.NullHandleRef,
                                     frameUnit,
                                     description,
                                     out metafile));
            }
            else
            {
                Gdip.CheckStatus(Gdip.GdipRecordMetafileFileNameI(
                                     fileName,
                                     new HandleRef(null, referenceHdc),
                                     type,
                                     ref frameRect,
                                     frameUnit,
                                     description,
                                     out metafile));
            }

            SetNativeImage(metafile);
        }
Exemple #29
0
		public Metafile (string fileName, IntPtr referenceHdc, RectangleF frameRect, MetafileFrameUnit frameUnit,
			EmfType type, string description) 
		{
			Status status = GDIPlus.GdipRecordMetafileFileName (fileName, referenceHdc, type, ref frameRect, frameUnit, 
				description, out nativeObject);
			GDIPlus.CheckStatus (status);
		}
        /// <summary>
        /// Initializes a new instance of the <see cref='Metafile'/> class with the specified filename.
        /// </summary>
        public Metafile(Stream stream, IntPtr referenceHdc, RectangleF frameRect, MetafileFrameUnit frameUnit, EmfType type, string description)
        {
            Gdip.CheckStatus(Gdip.GdipRecordMetafileStream(
                                 new GPStream(stream),
                                 new HandleRef(null, referenceHdc),
                                 type,
                                 ref frameRect,
                                 frameUnit,
                                 description,
                                 out IntPtr metafile));

            SetNativeImage(metafile);
        }
Exemple #31
0
        public Metafile(IntPtr referenceHdc, RectangleF frameRect, MetafileFrameUnit frameUnit, EmfType type,
                        string description)
        {
            int status = Gdip.GdipRecordMetafile(referenceHdc, type, ref frameRect, frameUnit,
                                                 description, out nativeImage);

            Gdip.CheckStatus(status);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref='Metafile'/> class with the specified filename.
        /// </summary>
        public Metafile(Stream stream, IntPtr referenceHdc, Rectangle frameRect, MetafileFrameUnit frameUnit, EmfType type, string description)
        {
            IntPtr metafile = IntPtr.Zero;

            if (frameRect.IsEmpty)
            {
                Gdip.CheckStatus(Gdip.GdipRecordMetafileStream(
                                     new GPStream(stream),
                                     new HandleRef(null, referenceHdc),
                                     type,
                                     NativeMethods.NullHandleRef,
                                     frameUnit,
                                     description,
                                     out metafile));
            }
            else
            {
                Gdip.CheckStatus(Gdip.GdipRecordMetafileStreamI(
                                     new GPStream(stream),
                                     new HandleRef(null, referenceHdc),
                                     type,
                                     ref frameRect,
                                     frameUnit,
                                     description,
                                     out metafile));
            }

            SetNativeImage(metafile);
        }
Exemple #33
0
 public Metafile(string fileName, IntPtr referenceHdc, RectangleF frameRect, MetafileFrameUnit frameUnit,
                 EmfType type) : this(fileName, referenceHdc, frameRect, frameUnit, type, null)
 {
 }
        /// <include file='doc\Metafile.uex' path='docs/doc[@for="Metafile.Metafile10"]/*' />
        /// <devdoc>
        ///    <para>
        ///       Initializes a new instance of the <see cref='System.Drawing.Imaging.Metafile'/> class from the specified device context,
        ///       bounded by the specified rectangle.
        ///    </para>
        /// </devdoc>
        public Metafile(IntPtr referenceHdc, RectangleF frameRect, MetafileFrameUnit frameUnit, EmfType type, String description)
        {
            IntSecurity.ObjectFromWin32Handle.Demand();

            IntPtr metafile = IntPtr.Zero;

            GPRECTF rectf  = new GPRECTF(frameRect);
            int     status = SafeNativeMethods.GdipRecordMetafile(new HandleRef(null, referenceHdc), (int)type, ref rectf, (int)frameUnit,
                                                                  description, out metafile);

            if (status != SafeNativeMethods.Ok)
            {
                throw SafeNativeMethods.StatusException(status);
            }

            SetNativeImage(metafile);
        }
Exemple #35
0
 internal static extern int GdipRecordMetafileStreamI(Interop.Ole32.IStream stream, IntPtr referenceHdc, EmfType emfType, ref Rectangle frameRect, MetafileFrameUnit frameUnit, string?description, out IntPtr metafile);
        /// <include file='doc\Metafile.uex' path='docs/doc[@for="Metafile.Metafile27"]/*' />
        /// <devdoc>
        ///    <para>
        ///       Initializes a new instance of the <see cref='System.Drawing.Imaging.Metafile'/> class with the
        ///       specified filename.
        ///    </para>
        /// </devdoc>
        public Metafile(string fileName, IntPtr referenceHdc, Rectangle frameRect, MetafileFrameUnit frameUnit, EmfType type, string description)
        {
            IntSecurity.DemandReadFileIO(fileName);
            IntSecurity.ObjectFromWin32Handle.Demand();

            IntPtr metafile = IntPtr.Zero;

            int status;

            if (frameRect.IsEmpty)
            {
                status = SafeNativeMethods.GdipRecordMetafileFileName(fileName, new HandleRef(null, referenceHdc), (int)type, NativeMethods.NullHandleRef, (int)frameUnit,
                                                                      description, out metafile);
            }
            else
            {
                GPRECT gprect = new GPRECT(frameRect);
                status = SafeNativeMethods.GdipRecordMetafileFileNameI(fileName, new HandleRef(null, referenceHdc), (int)type,
                                                                       ref gprect, (int)frameUnit,
                                                                       description, out metafile);
            }

            if (status != SafeNativeMethods.Ok)
            {
                throw SafeNativeMethods.StatusException(status);
            }

            SetNativeImage(metafile);
        }
        public Metafile(Stream stream, IntPtr referenceHdc, EmfType type, string description)
        {
            IntSecurity.ObjectFromWin32Handle.Demand();
            IntPtr metafile = IntPtr.Zero;

            int status = SafeNativeMethods.Gdip.GdipRecordMetafileStream(new GPStream(stream), 
                                                          new HandleRef(null, referenceHdc), 
                                                          unchecked((int)type),  
                                                          NativeMethods.NullHandleRef,
                                                          unchecked((int)MetafileFrameUnit.GdiCompatible), 
                                                          description,
                                                          out metafile);

            if (status != SafeNativeMethods.Gdip.Ok)
                throw SafeNativeMethods.Gdip.StatusException(status);

            SetNativeImage(metafile);
        }        
Exemple #38
0
        /// <summary>
        /// Initializes a new instance of the <see cref='Metafile'/> class from the specified device context, bounded
        /// by the specified rectangle.
        /// </summary>
        public Metafile(IntPtr referenceHdc, RectangleF frameRect, MetafileFrameUnit frameUnit, EmfType type, string description)
        {
            Gdip.CheckStatus(Gdip.GdipRecordMetafile(
                                 referenceHdc,
                                 type,
                                 ref frameRect,
                                 frameUnit,
                                 description,
                                 out IntPtr metafile));

            SetNativeImage(metafile);
        }
 internal static extern int GdipRecordMetafileStreamI(IntPtr stream, IntPtr referenceHdc, EmfType emfType, Rectangle *frameRect, MetafileFrameUnit frameUnit, string?description, IntPtr *metafile);
Exemple #40
0
 /// <summary>
 /// Initializes a new instance of the <see cref='Metafile'/> class with the specified filename.
 /// </summary>
 public Metafile(string fileName, IntPtr referenceHdc, EmfType type) :
     this(fileName, referenceHdc, type, null)
 {
 }
Exemple #41
0
		internal static extern Status GdipRecordMetafileFileNameI ([MarshalAs (UnmanagedType.LPWStr)] string filename, IntPtr hdc, EmfType type,
			ref Rectangle frameRect, MetafileFrameUnit frameUnit, [MarshalAs (UnmanagedType.LPWStr)] string description, out IntPtr metafile);
Exemple #42
0
        /// <summary>
        /// Initializes a new instance of the <see cref='Metafile'/> class with the specified filename.
        /// </summary>
        public Metafile(string fileName, IntPtr referenceHdc, RectangleF frameRect, MetafileFrameUnit frameUnit, EmfType type, string description)
        {
            // Called in order to emulate exception behavior from netfx related to invalid file paths.
            Path.GetFullPath(fileName);
            if (fileName.Length > MaxPath)
            {
                throw new PathTooLongException();
            }

            Gdip.CheckStatus(Gdip.GdipRecordMetafileFileName(
                                 fileName,
                                 referenceHdc,
                                 type,
                                 ref frameRect,
                                 frameUnit,
                                 description,
                                 out IntPtr metafile));

            SetNativeImage(metafile);
        }
Exemple #43
0
		static internal extern Status GdipRecordMetafileFromDelegateI_linux (StreamGetHeaderDelegate getHeader, 
			StreamGetBytesDelegate getBytes, StreamPutBytesDelegate putBytes, StreamSeekDelegate doSeek, 
			StreamCloseDelegate close, StreamSizeDelegate size, IntPtr hdc, EmfType type, ref Rectangle frameRect, 
			MetafileFrameUnit frameUnit, [MarshalAs (UnmanagedType.LPWStr)] string description, out IntPtr metafile);
Exemple #44
0
 /// <summary>
 /// Initializes a new instance of the <see cref='Metafile'/> class from the specified data stream.
 /// </summary>
 public Metafile(Stream stream, IntPtr referenceHdc, EmfType type) :
     this(stream, referenceHdc, type, null)
 {
 }
	public Metafile(IntPtr referenceHdc, EmfType emfType)
			: this(referenceHdc, emfType, null) {}
		public Metafile(EmfType type)
		{
			CreateInternalMetafile(type);	
		}
	public Metafile(String fileName, IntPtr referenceHdc, EmfType type)
			: this(fileName, referenceHdc, type, null) {}
Exemple #48
0
		public Metafile (Stream stream, IntPtr referenceHdc, EmfType type) :
			this (stream, referenceHdc, new RectangleF (), MetafileFrameUnit.GdiCompatible, type, null)
		{
		}
	public Metafile(String fileName, IntPtr referenceHdc,
					Rectangle frameRect, MetafileFrameUnit frameUnit,
					EmfType type, String description)
			{
				// TODO
			}
Exemple #50
0
		public Metafile (string fileName, IntPtr referenceHdc, EmfType type, string description) :
			this (fileName, referenceHdc, new RectangleF (), MetafileFrameUnit.GdiCompatible, type, description)
		{
		}
Exemple #51
0
		public Metafile (IntPtr referenceHdc, EmfType emfType, string description) :
			this (referenceHdc, new RectangleF (), MetafileFrameUnit.GdiCompatible, emfType, description)
		{
		}
Exemple #52
0
 public Metafile(string fileName, IntPtr referenceHdc, EmfType type, string description)
 {
     throw new NotImplementedException();
 }
Exemple #53
0
		public Metafile (IntPtr referenceHdc, Rectangle frameRect, MetafileFrameUnit frameUnit, EmfType type) :
			this (referenceHdc, frameRect, frameUnit, type, null)
		{
		}
Exemple #54
0
 public Metafile(IntPtr referenceHdc, EmfType emfType, string description) :
     this(referenceHdc, new RectangleF(), MetafileFrameUnit.GdiCompatible, emfType, description)
 {
 }
Exemple #55
0
		public Metafile (Stream stream, IntPtr referenceHdc, RectangleF frameRect, MetafileFrameUnit frameUnit,
			EmfType type) : this (stream, referenceHdc, frameRect, frameUnit, type, null)
		{
		}
Exemple #56
0
 public Metafile(Stream stream, IntPtr referenceHdc, EmfType type) :
     this(stream, referenceHdc, new RectangleF(), MetafileFrameUnit.GdiCompatible, type, null)
 {
 }
Exemple #57
0
		public Metafile (Stream stream, IntPtr referenceHdc, RectangleF frameRect, MetafileFrameUnit frameUnit, 
			EmfType type, string description) 
		{
			if (stream == null)
				throw new NullReferenceException ("stream");

			Status status = Status.NotImplemented;
			if (GDIPlus.RunningOnUnix ()) {
				// With libgdiplus we use a custom API for this, because there's no easy way
				// to get the Stream down to libgdiplus. So, we wrap the stream with a set of delegates.
				GDIPlus.GdiPlusStreamHelper sh = new GDIPlus.GdiPlusStreamHelper (stream, false);
				status = GDIPlus.GdipRecordMetafileFromDelegate_linux (sh.GetHeaderDelegate, sh.GetBytesDelegate, 
					sh.PutBytesDelegate, sh.SeekDelegate, sh.CloseDelegate, sh.SizeDelegate, referenceHdc, 
					type, ref frameRect, frameUnit, description, out nativeObject);
			} else {
				status = GDIPlus.GdipRecordMetafileStream (new ComIStreamWrapper (stream), referenceHdc, 
					type, ref frameRect, frameUnit, description, out nativeObject);
			}
			GDIPlus.CheckStatus (status);
		}
Exemple #58
0
 public Metafile(IntPtr referenceHdc, Rectangle frameRect, MetafileFrameUnit frameUnit, EmfType type) :
     this(referenceHdc, frameRect, frameUnit, type, null)
 {
 }
Exemple #59
0
 public Metafile GetMetafile(EmfType type)
 {
     int w = this.ClientRectangle.Width;
     int h = this.ClientRectangle.Height;
     Metafile metafile;
     using (var g = CreateGraphics())
     {
         IntPtr hdc = g.GetHdc();
         metafile = new Metafile(hdc, type);
         g.ReleaseHdc(hdc);
     }
     using (var g = Graphics.FromImage(metafile))
         DoPaint(g, w, h);
     return metafile;
 }
Exemple #60
0
 public Metafile(string fileName, IntPtr referenceHdc, EmfType type, string description) :
     this(fileName, referenceHdc, new RectangleF(), MetafileFrameUnit.GdiCompatible, type, description)
 {
 }