using System.Drawing; class Program { static void Main(string[] args) { // Load an image from file Image image = Image.FromFile(@"C:\MyImages\test.png"); // Use the image object as needed // ... // Dispose of the image object to free up resources image.Dispose(); } }
using System.Drawing; class Program { static void Main(string[] args) { // Load an image from file Image image = Image.FromFile(@"C:\MyImages\test.png"); // Create a bitmap object from the image Bitmap bitmap = new Bitmap(image); // Use the bitmap object as needed // ... // Dispose of the bitmap and image objects to free up resources bitmap.Dispose(); image.Dispose(); } }This example loads an image from a file located at "C:\MyImages\test.png" and stores it in an image object. It then creates a bitmap object from the image and uses it as needed before disposing of both the bitmap and image objects to free up resources. The System.Drawing namespace is part of the .NET Framework, which is included with Visual Studio and can also be downloaded separately.