Image.FromFile Method (String, Boolean)


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

Creates an Image from the specified file using embedded color management information in that file.

Namespace:   System.Drawing
Assembly:  System.Drawing (in System.Drawing.dll)

public static Image FromFile(
	string filename,
	bool useEmbeddedColorManagement


Type: System.String

A string that contains the name of the file from which to create the Image.

Type: System.Boolean

Set to true to use color management information embedded in the image file; otherwise, false.

Return Value

Type: System.Drawing.Image

The Image this method creates.

Exception Condition

The file does not have a valid image format.


GDI+ does not support the pixel format of the file.


The specified file does not exist.


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.


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 void Button2_Click(System.Object sender, System.EventArgs e)
        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();
            new RectangleF(90.0F, 110.0F, 100, 100));

        MessageBox.Show("There was an error opening the bitmap." +
            "Please check the path.");


.NET Framework
Available since 1.1
Return to top