private static Image GetImageFromParams(object pict, IntPtr handle, int pictype, IntPtr paletteHandle, int width, int height) { switch (pictype) { case -1: return null; case 0: return null; case 1: return Image.FromHbitmap(handle, paletteHandle); case 2: { var wmfHeader = new WmfPlaceableFileHeader(); wmfHeader.BboxRight = (short) width; wmfHeader.BboxBottom = (short) height; var metafile = new Metafile(handle, wmfHeader, false); return (Image) RuntimeHelpers.GetObjectValue(metafile.Clone()); } case 4: { var metafile2 = new Metafile(handle, false); return (Image) RuntimeHelpers.GetObjectValue(metafile2.Clone()); } } throw new Exception("AXUnknownImage"); }
public Metafile(IntPtr hmetafile, WmfPlaceableFileHeader wmfHeader, bool deleteWmf) { IntSecurity.ObjectFromWin32Handle.Demand(); IntPtr metafile = IntPtr.Zero; int status = SafeNativeMethods.Gdip.GdipCreateMetafileFromWmf(new HandleRef(null, hmetafile), deleteWmf, wmfHeader, out metafile); if (status != SafeNativeMethods.Gdip.Ok) throw SafeNativeMethods.Gdip.StatusException(status); SetNativeImage(metafile); }
public void DefaultValues () { WmfPlaceableFileHeader wh = new WmfPlaceableFileHeader (); Assert.AreEqual (0, wh.BboxBottom, "BboxBottom"); Assert.AreEqual (0, wh.BboxLeft, "BboxLeft"); Assert.AreEqual (0, wh.BboxRight, "BboxRight"); Assert.AreEqual (0, wh.BboxTop, "BboxTop"); Assert.AreEqual (0, wh.Checksum, "Checksum"); Assert.AreEqual (0, wh.Hmf, "Hmf"); Assert.AreEqual (0, wh.Inch, "Inch"); Assert.AreEqual (unchecked ((int)0x9AC6CDD7), wh.Key, "Key"); // always (from documentation) Assert.AreEqual (0, wh.Reserved, "Reserved"); }
public void Max () { WmfPlaceableFileHeader wh = new WmfPlaceableFileHeader (); wh.BboxBottom = short.MaxValue; Assert.AreEqual (short.MaxValue, wh.BboxBottom, "BboxBottom"); wh.BboxLeft = short.MaxValue; Assert.AreEqual (short.MaxValue, wh.BboxLeft, "BboxLeft"); wh.BboxRight = short.MaxValue; Assert.AreEqual (short.MaxValue, wh.BboxRight, "BboxRight"); wh.BboxTop = short.MaxValue; Assert.AreEqual (short.MaxValue, wh.BboxTop, "BboxTop"); wh.Checksum = short.MaxValue; Assert.AreEqual (short.MaxValue, wh.Checksum, "Checksum"); wh.Hmf = short.MaxValue; Assert.AreEqual (short.MaxValue, wh.Hmf, "Hmf"); wh.Inch = short.MaxValue; Assert.AreEqual (short.MaxValue, wh.Inch, "Inch"); wh.Key = int.MaxValue; Assert.AreEqual (int.MaxValue, wh.Key, "Key"); wh.Reserved = int.MaxValue; Assert.AreEqual (int.MaxValue, wh.Reserved, "Reserved"); }
public static MetafileHeader GetMetafileHeader (IntPtr hmetafile, WmfPlaceableFileHeader wmfHeader) { Metafile file = new Metafile(hmetafile, wmfHeader); MetafileHeader header = file.GetMetafileHeader(); file.Detach(); return header; }
public Metafile(IntPtr hmetafile, WmfPlaceableFileHeader wmfHeader, bool deleteWmf) { // TODO }
private static Image GetPictureFromParams(object pict, IntPtr handle, int type, IntPtr paletteHandle, int width, int height) { switch (type) { case -1: return null; case 0: return null; case 1: return Image.FromHbitmap(handle, paletteHandle); case 2: { WmfPlaceableFileHeader wmfHeader = new WmfPlaceableFileHeader { BboxRight = (short) width, BboxBottom = (short) height }; return (Image) new Metafile(handle, wmfHeader, false).Clone(); } case 3: return (Image) Icon.FromHandle(handle).Clone(); case 4: return (Image) new Metafile(handle, false).Clone(); } throw new ArgumentException(System.Windows.Forms.SR.GetString("AXUnknownImage"), "type"); }
// Convenience wrappers for the main constructors. public Metafile(IntPtr hmetafile, WmfPlaceableFileHeader wmfHeader) : this(hmetafile, wmfHeader, false) {}
private static Image GetPictureFromParams(object pict, IntPtr handle, int type, IntPtr paletteHandle, int width, int height) { switch (type) { case NativeMethods.Ole.PICTYPE_ICON: return(Image)(Icon.FromHandle(handle)).Clone(); case NativeMethods.Ole.PICTYPE_METAFILE: WmfPlaceableFileHeader header = new WmfPlaceableFileHeader(); header.BboxRight = (short)width; header.BboxBottom = (short)height; return(Image)(new Metafile(handle, header, false)).Clone(); case NativeMethods.Ole.PICTYPE_ENHMETAFILE: return(Image)(new Metafile(handle, false)).Clone(); case NativeMethods.Ole.PICTYPE_BITMAP: return Image.FromHbitmap(handle, paletteHandle); case NativeMethods.Ole.PICTYPE_NONE: // MSDN sez this should not be a valid value, but comctl32 returns it... return null; case NativeMethods.Ole.PICTYPE_UNINITIALIZED: return null; default: Debug.Fail("Invalid image type "+ type.ToString(CultureInfo.InvariantCulture)); throw new ArgumentException(SR.GetString(SR.AXUnknownImage), "type"); } }
internal static extern Status GdipCreateMetafileFromWmf (IntPtr hWmf, bool deleteWmf, WmfPlaceableFileHeader wmfPlaceableFileHeader, out IntPtr metafile);
internal static extern int GdipCreateMetafileFromWmf(HandleRef hMetafile, WmfPlaceableFileHeader wmfplacealbeHeader, bool deleteWmf, out IntPtr metafile);
public static MetafileHeader GetMetafileHeader(IntPtr hmetafile, WmfPlaceableFileHeader wmfHeader) { IntSecurity.ObjectFromWin32Handle.Demand(); MetafileHeader header = new MetafileHeader(); header.wmf = new MetafileHeaderWmf(); int status = SafeNativeMethods.Gdip.GdipGetMetafileHeaderFromWmf(new HandleRef(null, hmetafile), wmfHeader, header.wmf); if (status != SafeNativeMethods.Gdip.Ok) throw SafeNativeMethods.Gdip.StatusException(status); return header; }
public Metafile (IntPtr hmetafile, WmfPlaceableFileHeader wmfHeader, bool deleteWmf) { Status status = GDIPlus.GdipCreateMetafileFromEmf (hmetafile, deleteWmf, out nativeObject); GDIPlus.CheckStatus (status); }
public Metafile(IntPtr hmetafile, WmfPlaceableFileHeader wmfHeader, bool deleteWmf) { System.Drawing.IntSecurity.ObjectFromWin32Handle.Demand(); IntPtr zero = IntPtr.Zero; int status = SafeNativeMethods.Gdip.GdipCreateMetafileFromWmf(new HandleRef(null, hmetafile), wmfHeader, deleteWmf, out zero); if (status != 0) { throw SafeNativeMethods.Gdip.StatusException(status); } base.SetNativeImage(zero); }
public Metafile (IntPtr hmetafile, WmfPlaceableFileHeader wmfHeader) { throw new NotImplementedException (); }
internal static extern int GdipCreateMetafileFromWmf(HandleRef hMetafile, [MarshalAs(UnmanagedType.Bool)]bool deleteWmf, WmfPlaceableFileHeader wmfplacealbeHeader, out IntPtr metafile);
internal static extern int GdipGetMetafileHeaderFromWmf(HandleRef hMetafile, // WMF WmfPlaceableFileHeader wmfplaceable, [In, Out] MetafileHeaderWmf metafileHeaderWmf);
public static MetafileHeader GetMetafileHeader (IntPtr henhmetafile, WmfPlaceableFileHeader wmfHeader) { IntPtr header = Marshal.AllocHGlobal (Marshal.SizeOf (typeof (MetafileHeader))); try { Status status = GDIPlus.GdipGetMetafileHeaderFromEmf (henhmetafile, header); GDIPlus.CheckStatus (status); return new MetafileHeader (header); } finally { Marshal.FreeHGlobal (header); } }
public Metafile(IntPtr hmetafile, WmfPlaceableFileHeader wmfHeader) { int status = Gdip.GdipCreateMetafileFromEmf(hmetafile, false, out nativeImage); Gdip.CheckStatus(status); }