High-DPI - how to avoid automatic scaling of images

How to prevent scaling of image (with method like DrawImageAt() for example) when High-DPI scale factor > 1. I see image is automatically scaled according to that factor. Can i avoid this … i wan’t to use different image for different scale factor/resolution, without automatic JUCE rescaling ??

Of course i want all other things in my app to be scaled automatically by JUCE as expected.

I’ve been doing some work in this area. You can find out the scale factor using:

Which will be 1 for standard screens and 2 for Retina screens. I’m not sure about Windows, I think I read 1.25 is used.

drawImage() will scale an image to fit a rectangle, but drawImageAt() doesn’t scale it.

What I do is store all my images in high res on disk, and when the app is resized, I reload them and resize them in memory to the exact dimensions I need for the current GUI size / scale factor.

Drawing the images without having to scale them was quite a bit faster.

I am on Windows - getPhysicalPixelScaleFactor() returns 1 for my main (non-scaled) monitor and 1.5 for my hires monitor (scaled to 150%).

For testing purposes i am using images with size 100 x 100 for both factors 1 and 1.5. I am actually using drawImageAt().

On monitor with factor 1 everything is normal, as expected.

Also on monitor with 1.5 factor, i see my displayed image scaled (not smaller as i would expect), despite the same, 100x100 image size and higher resolution - JUCE automatically scaled it and this is something i want to avoid.

I think it’s happening at very low level, native screen painting code - i understand it’s because of that JUCE is resizing everything automatically on scaled monitors, without user intervention. But i want to prevent this with my images.

Code from juce_win32_Windowing.cpp performPaint() method:

context->addTransform (AffineTransform::scale ((float) getPlatformScaleFactor()));

This is not the same thing as scaling, which is happening with DrawImage() method (regardless of scale factor), when target rectangle is larger than image. JUCE is auto-scaling it because of scaled monitor resolution.

I hope i am clear enough. Not sure, maybe i am missing something or there’s something i don’t understand completely.

Thx for help!

Hmm. What exactly are you trying to do? Use different sets of images for each screen DPI resolution?

Yes, exactly, it’s very basic … i want do display different set of images, with different dimension for each resolution, without being resized automatically by JUCE (or by Windows).

This is a problem I have too, but I’ve still not solved. I have too many images to draw, so for a dpi 1:1, I had an unique class which resize them and scale to the desired size. Later, a paint method only needs to get a reference and paint it using g.drawImageAt().

Now I’m going to work with dpi, I was thinking into pre-size these images with the desired size multiplied by the dpi or physical/logic relationship, and then using the same mechanics. However this is in my head alone, I didn’t test it.

The “problem” is, that if your app is HiDPI aware, JUCE will automatically scale ALL displayed images using scale factor of HiDPI display (tested on Windows). If you need it to work this way, that’s very helpful. But if you want to avoid it, it’s not an easy task to do.

I want to avoid this scaling, because i already have full quality images with different sizes for different resolutions and i don’t need JUCE to scale them in any case. The only way i can think of, is to declare my app as HiDPI unaware and then do manual rescaling of every single element in GUI.