Ethan Allen
Ethan Allen

Reputation: 14835

How do I save WriteableBitmap to a file with a specific size with Windows Forms?

I am using the following code in Windows Phone 7 to save a JPEG image with a specific size:

WriteableBitmap wBitmap = new WriteableBitmap(resizedImage);
MemoryStream m = new MemoryStream();
wBitmap.SaveJpeg(m, h, w, 0, 100);

I am getting the error:

"WritableBitmap does contain a definition for SaveJpeg"

How do I do the same thing on a desktop Windows Forms app with C#?

Upvotes: 2

Views: 1295

Answers (1)

user1228
user1228

Reputation:

Here's how you would do this (okay, was facetious, now am srs) using the JpegBitmapEncoder

//Assuming resizedImage is a BitmapSource
JpegBitmapEncoder encoder = new JpegBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(resizedImage));
using(var stream = File.Open(theAristocratsFilename))
    encoder.Save(stream);

Upvotes: 4

Related Questions