@Abraham Carrillo , Welcome to Microsoft Q&A, you could convert your image to Bitmap and then you could use Bitmap set the PixelFormat.
Here is a code example you could refer to.
private void button1_Click(object sender, EventArgs e)
{
Image img = Image.FromFile("C:\\Users\\Administrator\\Desktop\\Icon.bmp");
Console.WriteLine(img.PixelFormat);
var brr=ImageToByteArray(img);
Image newimg=byteArrayToImage(brr,img.PixelFormat);
Console.WriteLine(newimg.PixelFormat);
}
public byte[] ImageToByteArray(System.Drawing.Image imageIn)
{
using (var ms = new MemoryStream())
{
imageIn.Save(ms, imageIn.RawFormat);
return ms.ToArray();
}
}
public Image byteArrayToImage(byte[] byteArrayIn, PixelFormat format)
{
MemoryStream ms = new MemoryStream(byteArrayIn);
Image returnImage = Image.FromStream(ms);
Bitmap bitmap=(Bitmap)returnImage;
Bitmap clone = new Bitmap(bitmap.Width, bitmap.Height,format);
using (Graphics gr = Graphics.FromImage(clone))
{
gr.DrawImage(bitmap, new Rectangle(0, 0, clone.Width, clone.Height));
}
return clone;
}
Hope my code could help you.
Best Regards,
Jack
If the answer is the right solution, please click "Accept Answer" and upvote it.If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.