Creating Cached Retina Pictures via Code

I have a project that I’ve maintained for a number of years that has used a custom system to handle Retina pictures (before Xojo supported Retina natively). I am currently trying to rip out that custom system and port this over to Xojo’s built-in Retina support.

When drawing directly to a canvas or window Graphics object in the respective Paint events, this is not an issue. The image-sets that I have created draw correctly for the type of display they appear on using nothing more complex than DrawPicture statements. This is awesome and very simple.

However, this project has a number of custom controls that are Canvas subclasses that handle their own drawing. When these controls are first initialized, they create their custom graphics and cache them in picture properties. This is where I’m getting hung up. I’ve tried a couple of different things, but I can only seem to create non-Retina pictures if I’m not drawing directly to the Canvas’ graphics object.

Can anyone point me in the right direction to do what I’m trying to do?

Thank you in advance!

Why do you need to redo the custom controls when everything works?

If you want to do the change show us your code.

Everything is working, true. I’m just wanting to “future-proof” the Retina support. Plus, I want to learn how to do this correctly for any future new projects.

  1. To make your custom control future proof, do not cache it to any picture, draw directly to the canvas graphics and let the OS rasterize it at the correct resolution to the device, be it a screen, printer or whatever.

  2. I suspect that your cache is still in 1x while you’re trying to display 2x content. You need to create a cache image that has the same amount of pixels as what the control has. Xojo has some functions, check their HI-DPI documentation for the names. p.s. Don’t forget to update the cache when the window changes screen.