I load image using this code:
OpenFileDialog ofd = new OpenFileDialog();
ofd.Title = "Select a Picture";
ofd.InitialDirectory = @"PATH";
if (ofd.ShowDialog() == DialogResult.OK)
{
HostImageLocationTxt.Text = ofd.FileName;
hostImage.Image = new Bitmap(ofd.FileName);
}
then , I load the image in another "PictureBox" and save the image without any modification using this code:
if (transformedImage.Image != null)
{
Bitmap bmp = new Bitmap(transformedImage.Image);
SaveFileDialog sfd = new SaveFileDialog();
sfd.Title = "Select Save Location";
sfd.InitialDirectory = @"PATH";
sfd.AddExtension = true;
if (sfd.ShowDialog() == DialogResult.OK)
{
switch (Path.GetExtension(sfd.FileName).ToUpper())
{
case ".BMP":
bmp.Save(sfd.FileName, ImageFormat.Bmp);
break;
case ".gif":
bmp.Save(sfd.FileName, ImageFormat.Gif);
break;
case ".JPG":
bmp.Save(sfd.FileName, ImageFormat.Jpeg);
break;
case ".JPEG":
bmp.Save(sfd.FileName,ImageFormat.Jpeg);
break;
case ".PNG":
bmp.Save(sfd.FileName, ImageFormat.Png);
break;
case ".png":
bmp.Save(sfd.FileName, ImageFormat.Png);
break;
default:
break;
}
}
}
The saved image result in different bit depth (Left: First Load Image , Right: Saved Image):
How to save it using same format it was loaded in the first?. Thank you.