retina graphics in a picture

When I draw into a graphics object (e.g. in a paint event) I can see the graphics are drawn in glorious retina quality.

However, when I create a new picture object and draw into p.graphic (e.g. so that I can crop, mask etc) , then draw that picture into the paint.graphics object, the graphics are non-retina - i.e. pixelated.

Drawing the picture at double size and then redrawing at the right size doesn’t fix the pixelation.

Is there an easy solution out there that I’m missing?

Get a Picture from Window.BitmapForCaching instead. See this blog post: Advanced Retina/HiDPI: BitmapForCaching and ScaleFactorChanged

Paul
It looks like it might be very clever but I don’t see how to apply it in this case.
I create pictures on the fly - inclusive of mask - drawing and masking different parts. Different pictures created for different elements to be printed both on-screen and to a printer.
The method that returns a picture can return a range of different pictures dependent on a range of properties.

  1. Would I need to create a cache for each and every variant?
  2. How do you handle masks on the cache?

It sounds like you maybe want to be try using the ScaleX/Y properties as described in Greg’s blog post:

Xojo Retina/HiDPI: The journey of a thousand pixels

That’s what I was looking for - thank you Paul

This is the downside to relying on using ‘scaling’ when preparing Retina assets. One thing I realised when learning how it’s done in Apple’s languages is for the most part it’s transparent when using high level api’s.

For instance, the NSImage APIs, allow you to create a blank image at a size (in points), then you use the NSDrawing APIs (which are somewhat funky) and draw to the image (all done in points). Then you set the image on the control or draw it into a View (or best use the drawing functions directly in the view), the OS will handle the correct resolution for you.

I really appreciate the simplicity of Xojo’s drawing APIs.

In the application that I’m working on now, there’s only two places where I have to actually worry about resolution, that with OpenGL (as it’s only pixel based) and CALayers (as they’re just weird). Everything else is automatically handled by the OS.

Once some more API is exposed to Xojo’s NSImage wrapper, mainly the ability to create a Xojo image picture from a NSImage ID, I want to port over some code that would make this a lot easier.

<https://xojo.com/issue/42528>