Wajahat Kareem
Wajahat Kareem

Reputation: 325

How to convert image-type to bitmap

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.

Upvotes: 5

Views: 13068

Answers (3)

Martin
Martin

Reputation: 1

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

Upvotes: 0

Oliver
Oliver

Reputation: 45119

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);

Upvotes: 1

user1968030
user1968030

Reputation:

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);

Upvotes: 7

Related Questions