In c#, I use Image to convert image from jpg -> png it will cropped. Even I set resolution, still the same
Here is the code:
Image image = Image.FromFile(imagePath);
image.Save("Image.png", ImageFormat.Png);
image.Dispose();
The result (I use android studio icon as example):
I use Image to convert image from jpg -> png it will cropped
>Solution :
Use the Bitmap namespace
static void ConvertJpgToPng(string imagePath)
{
using (Image image = Image.FromFile(imagePath))
{
// Create a new Bitmap with the same dimensions as the original image
Bitmap bitmap = new Bitmap(image.Width, image.Height);
// Create a Graphics object from the Bitmap
using (Graphics g = Graphics.FromImage(bitmap))
{
// Draw the original image onto the new Bitmap
g.DrawImage(image, 0, 0, image.Width, image.Height);
}
// Save the new Bitmap as PNG
bitmap.Save("Image.png", ImageFormat.Png);
}
}