public Bitmap(Stream stream, bool useIcm) { int num; if (stream == null) { throw new ArgumentException(System.Drawing.SR.GetString("InvalidArgument", new object[] { "stream", "null" })); } IntPtr zero = IntPtr.Zero; if (useIcm) { num = SafeNativeMethods.Gdip.GdipCreateBitmapFromStreamICM(new GPStream(stream), out zero); } else { num = SafeNativeMethods.Gdip.GdipCreateBitmapFromStream(new GPStream(stream), out zero); } if (num != 0) { throw SafeNativeMethods.Gdip.StatusException(num); } num = SafeNativeMethods.Gdip.GdipImageForceValidation(new HandleRef(null, zero)); if (num != 0) { SafeNativeMethods.Gdip.GdipDisposeImage(new HandleRef(null, zero)); throw SafeNativeMethods.Gdip.StatusException(num); } base.SetNativeImage(zero); Image.EnsureSave(this, null, stream); }
public Bitmap(string filename, bool useIcm) { int num; System.Drawing.IntSecurity.DemandReadFileIO(filename); filename = Path.GetFullPath(filename); IntPtr zero = IntPtr.Zero; if (useIcm) { num = SafeNativeMethods.Gdip.GdipCreateBitmapFromFileICM(filename, out zero); } else { num = SafeNativeMethods.Gdip.GdipCreateBitmapFromFile(filename, out zero); } if (num != 0) { throw SafeNativeMethods.Gdip.StatusException(num); } num = SafeNativeMethods.Gdip.GdipImageForceValidation(new HandleRef(null, zero)); if (num != 0) { SafeNativeMethods.Gdip.GdipDisposeImage(new HandleRef(null, zero)); throw SafeNativeMethods.Gdip.StatusException(num); } base.SetNativeImage(zero); Image.EnsureSave(this, filename, null); }
public Bitmap(Type type, string resource) { Stream manifestResourceStream = type.Module.Assembly.GetManifestResourceStream(type, resource); if (manifestResourceStream == null) { throw new ArgumentException(System.Drawing.SR.GetString("ResourceNotFound", new object[] { type, resource })); } IntPtr zero = IntPtr.Zero; int status = SafeNativeMethods.Gdip.GdipCreateBitmapFromStream(new GPStream(manifestResourceStream), out zero); if (status != 0) { throw SafeNativeMethods.Gdip.StatusException(status); } status = SafeNativeMethods.Gdip.GdipImageForceValidation(new HandleRef(null, zero)); if (status != 0) { SafeNativeMethods.Gdip.GdipDisposeImage(new HandleRef(null, zero)); throw SafeNativeMethods.Gdip.StatusException(status); } base.SetNativeImage(zero); Image.EnsureSave(this, null, manifestResourceStream); }