My application uses the camera to take a picture and upload it to flickr. I would like to compress the image down so that the download does not take as long as it is now. I tried both BitmapSource and WriteableBitmap 'SaveJpeg' to accomplish this, but failed. The bitmap source does not have the same elements available in Silverlight / WP, as happens in the full version of the .NET framework and in the SaveJpeg method, which WriteableBitmap continued to give me the error "This stream does not support writing."
This is what I am doing now in the CameraCaptureTask handled event handler:
private void CameraCaptureCompleted(object sender, PhotoResult e)
{
if (e == null || e.TaskResult != TaskResult.OK)
{
return;
}
BitmapImage bitmap = new BitmapImage {CreateOptions = BitmapCreateOptions.None};
bitmap.SetSource(AppHelper.LoadImage(e.ChosenPhoto));
WriteableBitmap writeableBitmap = new WriteableBitmap(bitmap);
writeableBitmap.SaveJpeg(e.ChosenPhoto, writeableBitmap.PixelWidth, writeableBitmap.PixelHeight, 0, 85);
}
This code gives me: Error "Stream does not support writing."
Is there any other way to compress the image or do I need to write a compression algorithm?
UPDATE FIXED !!
private void CameraCaptureCompleted(object sender, PhotoResult e)
{
if (e == null || e.TaskResult != TaskResult.OK)
{
return;
}
BitmapImage bitmap = new BitmapImage {CreateOptions = BitmapCreateOptions.None};
bitmap.SetSource(AppHelper.LoadImage(e.ChosenPhoto));
WriteableBitmap writeableBitmap = new WriteableBitmap(bitmap);
writeableBitmap.SaveJpeg(new MemoryStream(), writeableBitmap.PixelWidth, writeableBitmap.PixelHeight, 0, 85);
}
. Doh!
.