locked
compress an image opened by file picker before saving to document folder

    Question

  • Hi,

    Developing an app very similar to contact Phone book . Need to save contact image after compressing (only if image size > x KB) to some location in PC( let say Document folder) . How to Compress image before saving . Image is already on user's PC. Image is opened using File Picker  and saved using following  statement await file.CopyAsync( sf ,Name + ".jpg",NameCollisionOption.ReplaceExisting); where "file" = image_file picked by FilePicker and "sf"= storage Folder where i want to save the image.

    Monday, April 21, 2014 11:57 AM

Answers

  • JPGs are already compressed. If you want to compress it further you will need to reencode it. You'll have to read in the file through a BitmapDecoder and then reencode it at higher compression with a BitmapEncoder. For full instructions on selecting a file, creating an encoder, and encoding an image see How to encode an image

    Monday, April 21, 2014 3:02 PM
    Owner

All replies

  • JPGs are already compressed. If you want to compress it further you will need to reencode it. You'll have to read in the file through a BitmapDecoder and then reencode it at higher compression with a BitmapEncoder. For full instructions on selecting a file, creating an encoder, and encoding an image see How to encode an image

    Monday, April 21, 2014 3:02 PM
    Owner
  • Windows.Graphics.Imaging.BitmapEncoder offers half a dozen built-in compression formats (encoder IDs) including the common JPEG, GIF and PNG.
    These compression types are documented here:
    http://msdn.microsoft.com/en-us/library/windows/apps/windows.graphics.imaging.bitmapencoder.aspx#properties

    If the compression requirements exceed those offered by the BitmapEncoder class, you have 2 options: either create your own encoder, or use a dedicated imaging toolkit that supports Windows Store applications.

    There's a CodeProject article that shows a library with more compression options such as JPEG2000, JBIG and JBIG2 here:
    http://www.codeproject.com/Articles/470094/Image-Enabled-Windows-Store-Applications-with-LEAD

    Eddie Simpkins
    Tuesday, June 17, 2014 11:21 PM