How to convert image to 300 dpi in C#
By Tan Lee Published on Nov 26, 2024 688
To convert an image to 300 DPI in C#, you can use the System.Drawing namespace, specifically the Bitmap class.
How do you change the DPI of an image in C#?
Using the Bitmap
class, you load the image from the file. Then, use the SetResolution(float xDpi, float yDpi)
method to adjust the horizontal and vertical DPI of the image.
For example:
string inputFilePath = "input.jpg"; string outputFilePath = "output_300dpi.jpg"; // c# load the image file using (Bitmap bitmap = new Bitmap(inputFilePath)) { // Set the resolution to 300 DPI bitmap.SetResolution(300, 300); // Save the image with the new resolution bitmap.Save(outputFilePath, ImageFormat.Jpeg); }
The updated image is saved to a new file, preserving the DPI setting.
Categories
Popular Posts
Elegent Material UI React Admin Dashboard Template
Nov 19, 2024
Portal HTML Bootstrap
Nov 13, 2024
HTML Bootstrap 4 Login, Register & Reset Template
Nov 11, 2024
Freedash bootstrap lite
Nov 13, 2024