locked
Exception "The buffer allocated is insufficient" for BitmapEncoder

    Question

  • SetPixelData() of the following code generates the exception.

    InMemoryRandomAccessStream ras = new InMemoryRandomAccessStream();
    BitmapEncoder enc = await BitmapEncoder.CreateAsync(BitmapEncoder.JpegEncoderId, ras);
    
    ...
    
    enc.SetPixelData(BitmapPixelFormat.Rgba8, BitmapAlphaMode.Straight, bd.PixelWidth, bd.PixelHeight, 96.0, 96.0, abImage);

    How can the allocated buffer be increased?


    Hong

    Tuesday, September 16, 2014 1:51 PM

Answers

  • It is complaining about abImage.  How are you creating that, it appears to be too small.

    Bret Bentzinger (MSFT) @awehellyeah

    • Marked as answer by Hong (MA, USA) Tuesday, September 16, 2014 10:37 PM
    Tuesday, September 16, 2014 8:59 PM
    Moderator

All replies

  • It is complaining about abImage.  How are you creating that, it appears to be too small.

    Bret Bentzinger (MSFT) @awehellyeah

    • Marked as answer by Hong (MA, USA) Tuesday, September 16, 2014 10:37 PM
    Tuesday, September 16, 2014 8:59 PM
    Moderator
  • Thank you for the tip.  I never thought it complains about abImage which is created in different ways under different circumstances.  Though it should not happen, but it is possible that abImage !=  bd.PixelWidth *bd.PixelHeight * 4 due to wrong image file format.

    Hong

    Tuesday, September 16, 2014 10:40 PM