简体   繁体   中英

How to render java component to high resolution image?

I'm trying to extract an images of the application window's components in java.

I've created a class that overrides java.awt.GraphicsConfiguration and looks very similar to sun.awt.Win32GraphicsConfig . The problem is that when I call the createAcceleratedImage function with component (for example application window) and 2x larger dimensions than the real one, the java renders it small in the image on the top left corner and the rest of the image is empty space.

My createAcceleratedImage function is same as in sun.awt.Win32GraphicsConfig :

public Image createAcceleratedImage(Component target, int w, int h) {
    ColorModel localColorModel = getColorModel(Transparency.OPAQUE);
    WritableRaster localWritableRaster = localColorModel.createCompatibleWritableRaster(w, h);
    return new OffScreenImage(target, localColorModel, localWritableRaster, localColorModel.isAlphaPremultiplied());
}

I apologize if I forgot to mention more information, If you need more information please ask in comments.

Thank you for help.

I used VolatileImage instead of OffScreenImage inside my CustomComponentPeer.

public VolatileImage createVolatileImage(int width, int height) {
    GraphicsConfiguration graphicsConfig = getGraphicsConfiguration();
    return graphicsConfig.createCompatibleVolatileImage(width, height);
}

I found that drawImage function in Graphics2D support high resolution rendering only for MultiResolutionImage and VolatileImage. Rendering in high DPI using OffScreenImage is not supported.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM