Graphics.FromImage Method
Assembly: System.Drawing (in system.drawing.dll)
If the image has an indexed pixel format, this method throws an exception with the message, "A Graphics object cannot be created from an image that has an indexed pixel format." The indexed pixel formats are shown in the following list.
This method also throws an exception if the image has any of the following pixel formats.
You should always call the Dispose method to release the Graphics and related resources created by the FromImage method.
The following code example is designed for use with Windows Forms, and it requires PaintEventArgse, which is a parameter of the Paint event handler. The code performs the following action:
-
Creates an Image from a graphics file SampImag.jpg in the example folder.
-
Creates a Graphics from the Image.
-
Alters the image by filling a rectangle within it.
-
Draws the Image to the screen.
-
Releases the created Graphics.
Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.