Drawing HiDPI component to BufferedImage

Hendrik Schreiber hs at tagtraum.com
Fri Jan 24 05:23:43 PST 2014


On Jan 24, 2014, at 13:39, Alexander Scherbatiy <alexandr.scherbatiy at oracle.com> wrote:

> The API that allows to create custom images for HiDPI displays is only under discussion now.
> It can be found in the thread: http://mail.openjdk.java.net/pipermail/awt-dev/2014-January/006775.html
> It also contains a link to the patch that allows SunGraphics2D class to correctly draw multi-resolution images.
> 
> You can try to apply the patch to the JDK 9 and check that it works for your case.

Thanks, Alexandr.

I wasn't necessarily looking for special images that support HiDPI. I just wanted to be able to draw a standard component (e.g. a JButton) to a BufferedImage in a way that causes the component to be rendered *as if* the given BufferedImage supported high resolution.

Say the button is 16x16 pixels large in reg. DPI.
Then I'd love to render the thing to a 32x32 BufferedImage in HiDPI.
But other than rendering to the screen, there doesn't seem to be a way to convince the button that it should now render its HiDPI version.

Thanks.

-hendrik


> On 1/24/2014 12:05 PM, Hendrik Schreiber wrote:
>> Hey,
>> 
>> to animate a component, I usually draw it to a BufferedImage and then draw that image to the glass pane, where I can easily move it around without having to completely re-render the component all the time. Unfortunately, this technique does not work well on Retina/HiDPI displays, as I can't seem to be able to convince any components to render in high resolution to a BufferedImage.
>> 
>> Is there a way to paint components to BufferedImages in high resolution?
>> I'd like something like:
>> 
>>         final Image image = component.createImage(component.getWidth(), component.getHeight());
>>         component.paint(image.getGraphics());
>>         // then go on to use the image...
>> 
>> to work properly.
>> 
>> Thanks,
>> 
>> -hendrik
> 



More information about the macosx-port-dev mailing list