locked
RenderTargetBitmap.RenderAsync produces smaller than requested image dimensions

    Question

  • I have developed an app for the Windows Store called Text-O-Matic which is a text graphic editor. Simply, users place XAML elements on a canvas and Text-O-Matic uses RenderTargetBitmap.RenderAsync to save the result to an image file. It works quite well and is proving to be a very popular application!

    On some users' systems, RenderAsync does not render an image at the requested dimensions. For example, a user is trying to render a 4x6 (aspect ratio) image at 1200x1800 pixels. As far as I know, except for this one user, this is not an unreasonable request. It's far under the 4096x4096 2D texture limit mentioned in the documentation. However, this user gets an image at 856x1285. I asked him to try a full-screen 16:9 image at full resolution which should produce an image at 2560x1440. His system produces the image at 1828x1031.

    Needless to say, all of these resolutions work as expected on my system and any system I have ever tried, such a Surface 2 RT, Surface Pro, Dell Venue 11 Pro, cheapo Toshiba laptop, even an ancient Dell Optiplex Pentium machine, and many, many more. The user who is having the trouble is using a Dell Inspiron 15z Core i5 with 6GB of RAM, which is not an under-powered system!

    Why would RenderAsync arbitrarily reduce/limit the requested dimensions and how do I get around it?


    Thaine Norris

    Tuesday, September 16, 2014 10:51 PM

Answers

  • Herro got most of the way there.

    This sounds like a high DPI system at 140% scale (1/140% = 70%). You should be able to repro by going to your control panel / Appearance and Personalization / Display and using the "Change the size of all items" slider.

    See Scaling to pixel density and the Scaling according to DPI sample for guidelines on handling high DPI systems in your code.

    --Rob

    Thursday, September 18, 2014 5:39 AM
    Owner
  • Hi Rob,

    Thank you for your reply. You're right. The issue had to do with DPI. I was not considering the value of DisplayInformation.GetForCurrentView().ResolutionScale in computing the final dimensions passed to RenderTargetBitmap.RenderAsync. An undocumented "feature" of RenderAsync is that it readjusts the final output dimensions based on system DPI. I had to discover this empirically.

    The issue for me was that I have included a few dozen design templates in the application. These templates were created on a high DPI system and therefore rendered too small on a system with 100% scale. By using the ResolutionScale value and a scale transform on the XAML to be rendered, I was able to achieve the proper output dimensions.

    It sure would be nice if this issue was mentioned as part of the documentation on RenderTargetBitmap.RenderAsync. That would have saved me a lot of trouble and a few unhappy customers.

    Thanks again,


    Thaine Norris

    Thursday, September 18, 2014 2:04 PM

All replies

  • Hi Dtnorris,

    The user’s rendered image content keeps 70% scale ratio (856/1200, 1285/1800, 1828/2560, 1031/1440). It might be some issue on that user’s computer. You can ask that user to get into safe mode to run you app, this may help to understand if there is some third party softwares cause this problem. If it doesn’t work, I would recommend you consider to check that user’s computer hardware.

    An easy way to work around this problem, try to compare the PixelWidth and PixelHeight value with the requested value. Resize it when necessary.

    Here is some useful code snippet about how to resize image in windows store app. http://stackoverflow.com/questions/12349611/how-to-resize-image-in-c-sharp-winrt-winmd.

    Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, September 18, 2014 5:08 AM
    Moderator
  • Herro got most of the way there.

    This sounds like a high DPI system at 140% scale (1/140% = 70%). You should be able to repro by going to your control panel / Appearance and Personalization / Display and using the "Change the size of all items" slider.

    See Scaling to pixel density and the Scaling according to DPI sample for guidelines on handling high DPI systems in your code.

    --Rob

    Thursday, September 18, 2014 5:39 AM
    Owner
  • Hi Rob,

    Thank you for your reply. You're right. The issue had to do with DPI. I was not considering the value of DisplayInformation.GetForCurrentView().ResolutionScale in computing the final dimensions passed to RenderTargetBitmap.RenderAsync. An undocumented "feature" of RenderAsync is that it readjusts the final output dimensions based on system DPI. I had to discover this empirically.

    The issue for me was that I have included a few dozen design templates in the application. These templates were created on a high DPI system and therefore rendered too small on a system with 100% scale. By using the ResolutionScale value and a scale transform on the XAML to be rendered, I was able to achieve the proper output dimensions.

    It sure would be nice if this issue was mentioned as part of the documentation on RenderTargetBitmap.RenderAsync. That would have saved me a lot of trouble and a few unhappy customers.

    Thanks again,


    Thaine Norris

    Thursday, September 18, 2014 2:04 PM