/// <include file='doc\Bitmap.uex' path='docs/doc[@for="Bitmap.Bitmap3"]/*' /> /// <devdoc> /// Initializes a new instance of the /// <see cref='System.Drawing.Bitmap'/> /// class from the specified data stream. /// </devdoc> /** * Create a new bitmap object from a stream */ public Bitmap(Stream stream) { if (stream == null) { throw new ArgumentException(SR.GetString(SR.InvalidArgument, "stream", "null")); } IntPtr bitmap = IntPtr.Zero; int status = SafeNativeMethods.GdipCreateBitmapFromStream(new GPStream(stream), out bitmap); if (status != SafeNativeMethods.Ok) { throw SafeNativeMethods.StatusException(status); } status = SafeNativeMethods.GdipImageForceValidation(new HandleRef(null, bitmap)); if (status != SafeNativeMethods.Ok) { SafeNativeMethods.GdipDisposeImage(new HandleRef(null, bitmap)); throw SafeNativeMethods.StatusException(status); } SetNativeImage(bitmap); EnsureSave(this, null, stream); }
/// <include file='doc\Bitmap.uex' path='docs/doc[@for="Bitmap.Bitmap2"]/*' /> /// <devdoc> /// <para> /// Initializes a new instance of the <see cref='System.Drawing.Bitmap'/> class from a specified resource. /// </para> /// </devdoc> public Bitmap(Type type, string resource) { Stream stream = type.Module.Assembly.GetManifestResourceStream(type, resource); if (stream == null) { throw new ArgumentException(SR.GetString(SR.ResourceNotFound, type, resource)); } IntPtr bitmap = IntPtr.Zero; int status = SafeNativeMethods.GdipCreateBitmapFromStream(new GPStream(stream), out bitmap); if (status != SafeNativeMethods.Ok) { throw SafeNativeMethods.StatusException(status); } status = SafeNativeMethods.GdipImageForceValidation(new HandleRef(null, bitmap)); if (status != SafeNativeMethods.Ok) { SafeNativeMethods.GdipDisposeImage(new HandleRef(null, bitmap)); throw SafeNativeMethods.StatusException(status); } SetNativeImage(bitmap); EnsureSave(this, null, stream); }