How to Reduce Size of Image in windows phone

前端 未结 4 1580
说谎
说谎 2021-01-23 09:55

I am trying to port my app in windows phone . i have to upload an image on server So it is in small Size For uploading i have done this thing in Widows Successfully but problem

相关标签:
4条回答
  • 2021-01-23 10:00

    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.

    0 讨论(0)
  • 2021-01-23 10:01

    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

    0 讨论(0)
  • 2021-01-23 10:08

    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);
    .......
    
    0 讨论(0)
  • 2021-01-23 10:13

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

    0 讨论(0)
提交回复
热议问题