What's the best way to draw into and offscreen Image and be DPI independent?


#1

hi, 

What's the best way to use Graphics to draw into an offscreen Image and be able to get the extact same rendering on multi dpi screens?

For now I have to manually oversample the image according to the scale parameter reported by the Display class. But everything has to be scaled too (width, height, fontHeight, lineWidth...) and this is quite error prone.

Is there a simpler way to do it? After all that's exactly what the Graphics class does for when drawing directly to the screen, the code using it doesn't have to be aware of the scale factor. 


#2

Best thing to do is to re-draw your background image based on the DPI given to the Graphics object in your paint method. When that DPI changes, ditch your cached image and re-create it with the new DPI. When your window moves between monitors, that'll make it refresh.


#3

Hi Jules,

 

I think you have missed the point of teh question.

The question is more about how to draw inside an Image and simulate an HiDPI display in it.

Currently if you only scale the width and height of the Image, you will miss the adjustement made automaticly regarding line width, font size.

 

Hope this clarify things.


#4

Well, you can set the scale of the Graphics that you use to draw into the image to render at higher DPIs, I guess.


#5

How do you do that ?

using addTransform ?

 

Thanks !


#6

Yes, just add a scaling transform.


#7

Will try this. Thanks !