示例#1
0
        /// <include file='doc\Bitmap.uex' path='docs/doc[@for="Bitmap.Bitmap4"]/*' />
        /// <devdoc>
        ///    <para>
        ///       Initializes a new instance of the <see cref='System.Drawing.Bitmap'/> class from the specified data
        ///       stream.
        ///    </para>
        /// </devdoc>
        public Bitmap(Stream stream, bool useIcm)
        {
            if (stream == null)
            {
                throw new ArgumentException(SR.GetString(SR.InvalidArgument, "stream", "null"));
            }

            IntPtr bitmap = IntPtr.Zero;
            int    status;

            if (useIcm)
            {
                status = SafeNativeMethods.GdipCreateBitmapFromStreamICM(new GPStream(stream), out bitmap);
            }
            else
            {
                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);
        }