Exemple #1
0
        /*
         * Predefined bitmap data formats
         */

        /// <include file='doc\Bitmap.uex' path='docs/doc[@for="Bitmap.Bitmap"]/*' />
        /// <devdoc>
        ///    Initializes a new instance of the
        /// <see cref='System.Drawing.Bitmap'/>
        /// class from the specified file.
        /// </devdoc>

        /**
         * Create a new bitmap object from URL
         */
        public Bitmap(String filename)
        {
            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 = 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);
        }