5

I am making an application which works on .BMP and fixed size. I made the module for resizing but unable to convert PNG, JPEG and other picture formats to .bmp.

Is there any simple method, because of multiple compression schemes it is a lot difficult to write seperate module for each.

codeteq
  • 1,502
  • 7
  • 13
Wajahat Kareem
  • 325
  • 2
  • 4
  • 14

4 Answers4

7

use this

public BitmapImage ImageFromBuffer(Byte[] bytes)
{
    MemoryStream stream = new MemoryStream(bytes);
    BitmapImage image = new BitmapImage();
    image.BeginInit();
    image.StreamSource = stream;
    image.EndInit();
    return image;
}

or use this

Image Dummy = Image.FromFile("image.png");
Dummy.Save("image.bmp", ImageFormat.Bmp);
1

Every image that you have already loaded into memory is independent from the source format. After manipulation you can write it back to disk by using any format that is available by simply calling the Save() method with the desired format

var bmp1 = Image.FromFile("myJpegFile.jpg");
bmp1.Save("c:\\button.bmp", System.Drawing.Imaging.ImageFormat.Bmp);
Oliver
  • 43,366
  • 8
  • 94
  • 151
0

Well, please look at this question:

Convert to BMP

and

MSDN ImageFormat Members

using(Image img = Image.FromFile("image.png"))
{
    img.Save("image.bmp", ImageFormat.Bmp);
    // ...
}
Community
  • 1
  • 1
codeteq
  • 1,502
  • 7
  • 13
0

in Bitmap myBitmap = new Bitmap(); myBitmap.Save(, System.Drawing.Imaging.ImageFormat.Bmp);

is the problem, that transparency in pgnsourcefilepathanme is converted to black in bitmapdestfilepathname

Martin
  • 1
  • 1
  • Bitmap myBitmap = new Bitmap(pgnsourcefilepathanme); myBitmap.Save(bitmapdestfilepathname, System.Drawing.Imaging.ImageFormat.Bmp); – Martin Sep 01 '23 at 09:13