public static FromImage ( Image image ) : Graphics | ||
image | Image | |
return | Graphics |
// Load an image from a file var image = Image.FromFile("image.jpg"); // Create a new Graphics object for the image var graphics = Graphics.FromImage(image); // Draw a red line on the image var pen = new Pen(Color.Red); graphics.DrawLine(pen, 0, 0, 100, 100); // Save the modified image to a file image.Save("modified.jpg");
// Load an image from a file var image = Image.FromFile("image.jpg"); // Create a new Graphics object for the image var graphics = Graphics.FromImage(image); // Draw white text on the image var font = new Font("Arial", 24); var brush = new SolidBrush(Color.White); graphics.DrawString("Hello, world!", font, brush, 50, 50); // Save the modified image to a file image.Save("modified.jpg");In this example, we load an image from a file, create a new `Graphics` object for the image using the `Graphics.FromImage` method, draw white text on the image using the `DrawString` method of the `Graphics` object, and finally save the modified image to a file. Package library: `System.Drawing.dll` Overall, the `Graphics.FromImage` method is a powerful tool for working with images and graphics in C#. With it, developers can create custom charts, diagrams, banners, and much more. Additionally, a wide range of methods and properties are available through the `Graphics` object, providing a lot of flexibility in programming graphical applications.