locked
Controling Image Quality while writing a JPG

    Question

  • How can I create the third parameter to BitmapEncoder::CreateAsync

    static IAsyncOperation<BitmapEncoder>^ CreateAsync(   Guid encoderId,    IRandomAccessStream^ stream, 
                                                                                        IIterable<IKeyValuePair>^ encodingOptions
    )

    such that I can control the Image Quality ?

    The documentation says you can do it but it rather vague on exactly how.    

    "Remarks

    Bitmap encoders may expose various encoding options that affect the quality, size and other properties of the encoded output file. Because every file format is different, each encoder exposes a different set of options; for example the built-in JPEG encoder allows the application to specify parameters including image quality and subsampling mode. "

    "You can obtain a collection of key-value pairs that you can pass to the encodingOptions parameter by creating a new BitmapPropertySet. "

    http://msdn.microsoft.com/en-us/library/windows/apps/br226213.aspx#Y0

    Tuesday, August 28, 2012 5:30 PM

Answers

  • The options depend on the specific encoder. You can find documentation on the available ones in the documentation for the encoder you are using.

    For the JPEG encoder, see JPEG Format Overview .

    --Rob

    • Marked as answer by Andrew7Webb Thursday, August 30, 2012 5:06 PM
    Thursday, August 30, 2012 4:29 PM
    Owner

All replies

  • The options depend on the specific encoder. You can find documentation on the available ones in the documentation for the encoder you are using.

    For the JPEG encoder, see JPEG Format Overview .

    --Rob

    • Marked as answer by Andrew7Webb Thursday, August 30, 2012 5:06 PM
    Thursday, August 30, 2012 4:29 PM
    Owner
  • Thanks, this code worked for me.

    // How to control the quality of a encoded JPG
    using namespace Windows::Graphics::Imaging;

    BitmapPropertySet ^ bitmapPropertiesSet= ref new BitmapPropertySet();
    bitmapPropertiesSet->Insert( "ImageQuality", ref new BitmapTypedValue( 0.20, PropertyType::Single ) );

    task< BitmapEncoder^ > getEncoderTask( BitmapEncoder::CreateAsync( BitmapEncoder::JpegEncoderId, putJpgStream, bitmapPropertiesSet ) );
    getEncoderTask.then( [=] ( BitmapEncoder^ bitmapEncoder )
    {
       etc

    Thursday, August 30, 2012 5:08 PM