Exemplo n.º 1
0
        /// <include file='doc\Bitmap.uex' path='docs/doc[@for="Bitmap.Bitmap1"]/*' />
        /// <devdoc>
        ///    <para>
        ///       Initializes a new instance of the <see cref='System.Drawing.Bitmap'/> class from the specified
        ///       file.
        ///    </para>
        /// </devdoc>
        public Bitmap(String filename, bool useIcm)
        {
            IntSecurity.DemandReadFileIO(filename);

            //GDI+ will read this file multiple times.  Get the fully qualified path
            //so if our app changes default directory we won't get an error
            //
            filename = Path.GetFullPath(filename);

            IntPtr bitmap = IntPtr.Zero;
            int    status;

            if (useIcm)
            {
                status = SafeNativeMethods.GdipCreateBitmapFromFileICM(filename, out bitmap);
            }
            else
            {
                status = SafeNativeMethods.GdipCreateBitmapFromFile(filename, 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, filename, null);
        }