如何将java组件渲染成高分辨率图像



我正在尝试用java提取应用程序窗口组件的图像。

我创建了一个类,它覆盖了java.awt.GraphicsConfiguration,看起来与sun.awt.Win32GraphicsConfig非常相似。问题是,当我调用带有组件(例如应用程序窗口(和比实际尺寸大2倍的createAcceleratedImage函数时,java在左上角的图像中将它渲染得很小,图像的其余部分为空白。

我的createAcceleratedImage函数与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());
}

如果我忘记提及更多信息,我深表歉意。如果你需要更多信息,请在评论中询问。

谢谢你的帮助。

我在CustomComponentPeer中使用了VolatileImage而不是OffScreenImage。

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

我发现Graphics2D中的drawImage函数只支持MultiResolutionImage和VolatileImage的高分辨率渲染。不支持使用OffScreenImage以高DPI进行渲染。

最新更新