Creates an Image from the specified file using embedded color management information in that file.
Assembly: System.Drawing (in System.Drawing.dll)
Public Shared Function FromFile ( _ filename As String, _ useEmbeddedColorManagement As Boolean _ ) As Image
public static Image FromFile( string filename, bool useEmbeddedColorManagement )
public: static Image^ FromFile( String^ filename, bool useEmbeddedColorManagement )
static member FromFile : filename:string * useEmbeddedColorManagement:bool -> Image
Parameters
- filename
- Type: System.String
A string that contains the name of the file from which to create the Image.
- useEmbeddedColorManagement
- Type: System.Boolean
Set to true to use color management information embedded in the image file; otherwise, false.
| Exception | Condition |
|---|---|
| OutOfMemoryException |
The file does not have a valid image format. -or- GDI+ does not support the pixel format of the file. |
| FileNotFoundException |
The specified file does not exist. |
| ArgumentException |
filename is a Uri. |
Managed GDI+ has built-in encoders and decoders that support the following file types:
-
BMP
-
GIF
-
JPEG
-
PNG
-
TIFF
If the file does not have a valid image format or if GDI+ does not support the pixel format of the file, this method throws an OutOfMemoryException exception.
The file remains locked until the Image is disposed.
The useEmbeddedColorManagement parameter specifies whether the new Image applies color correction according to color management information that is embedded in the image file. Embedded information can include International Color Consortium (ICC) profiles, gamma values, and chromaticity information.
Note
|
|---|
|
The Image class does not support alpha transparency in bitmaps. To enable alpha transparency, use PNG images with 32 bits per pixel. |
The following code example demonstrates how to obtain a new bitmap using the FromFile method. It also demonstrates a TextureBrush.
This example is designed to be used with Windows Forms. Create a form containing a button named Button2. Paste the code into the form and associate the Button2_Click method with the button's Click event.
Private Sub Button2_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button2.Click Try Dim image1 As Bitmap = _ CType(Image.FromFile("C:\Documents and Settings\" _ & "All Users\Documents\My Music\music.bmp", True), Bitmap) Dim texture As New TextureBrush(image1) texture.WrapMode = Drawing2D.WrapMode.Tile Dim formGraphics As Graphics = Me.CreateGraphics() formGraphics.FillEllipse(texture, _ New RectangleF(90.0F, 110.0F, 100, 100)) formGraphics.Dispose() Catch ex As System.IO.FileNotFoundException MessageBox.Show("There was an error opening the bitmap." _ & "Please check the path.") End Try End Sub
private void Button2_Click(System.Object sender, System.EventArgs e) { try { Bitmap image1 = (Bitmap) Image.FromFile(@"C:\Documents and Settings\" + @"All Users\Documents\My Music\music.bmp", true); TextureBrush texture = new TextureBrush(image1); texture.WrapMode = System.Drawing.Drawing2D.WrapMode.Tile; Graphics formGraphics = this.CreateGraphics(); formGraphics.FillEllipse(texture, new RectangleF(90.0F, 110.0F, 100, 100)); formGraphics.Dispose(); } catch(System.IO.FileNotFoundException) { MessageBox.Show("There was an error opening the bitmap." + "Please check the path."); } }
private: void Button2_Click( System::Object^ /*sender*/, System::EventArgs^ /*e*/ ) { try { Bitmap^ image1 = dynamic_cast<Bitmap^>(Image::FromFile( "C:\\Documents and Settings\\" "All Users\\Documents\\My Music\\music.bmp", true )); TextureBrush^ texture = gcnew TextureBrush( image1 ); texture->WrapMode = System::Drawing::Drawing2D::WrapMode::Tile; Graphics^ formGraphics = this->CreateGraphics(); formGraphics->FillEllipse( texture, RectangleF(90.0F,110.0F,100,100) ); delete formGraphics; } catch ( System::IO::FileNotFoundException^ ) { MessageBox::Show( "There was an error opening the bitmap." "Please check the path." ); } }
.NET Framework
Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0.NET Framework Client Profile
Supported in: 4, 3.5 SP1Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Note