How to Reduce Size of Image in windows phone

只谈情不闲聊 提交于 2019-12-02 02:53:29

You should use WriteablBitmap to reduce size of image. WriteablBitmap has number of methods for images in windows phone Here is more about writeablebitmapex.

Try to load your original image to WriteableBitmap object, then you can use SaveJpeg() extension method from System.Windows.Media.Imaging namespace, to save new image with reduced size. For example :

.......
WriteableBitmap wb = new WriteableBitmap(bitmapImageObject);
wb.SaveJpeg(stream, 120, 160, 0, 100);
.......

When you are taking picture you can choose the resolution with which the picture will be taken. This can be done by

PhotoCamera cam; 

After camera initizalition.

Following code when image is capturing (in the method that captures the image)

IEnumerable<Size> resList = cam.AvailableResolutions;

Size res;
if (resList.Count() > 0)
{
    res = resList.ElementAt<Size>(0);
    cam.Resolution = res;

 }

This sample chooses the first resolution

You can try this. It worked for me. It reduced my 9.70MB file into 270KB.

WriteableBitmap cameraCapturedImage = PictureDecoder.DecodeJpeg(e.ChosenPhoto, 1024, 1024);

using (IsolatedStorageFileStream myFileStream = myStore.CreateFile(fileName))
{
  System.Windows.Media.Imaging.Extensions.SaveJpeg(cameraCapturedImage, myFileStream, cameraCapturedImage.PixelWidth, cameraCapturedImage.PixelHeight, 0, 85);
  myFileStream.Close();
}

N.B: fileName is the name of file to save size reduced image.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!