簡體   English   中英

如何將 java 組件渲染為高分辨率圖像?

[英]How to render java component to high resolution image?

我正在嘗試在 java 中提取應用程序窗口組件的圖像。

我創建了一個 class 覆蓋java.awt.GraphicsConfiguration並且看起來與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.

我的 createAcceleratedImage function 與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 function只支持MultiResolutionImage和VolatileImage的高分辨率渲染。 不支持使用 OffScreenImage 以高 DPI 渲染。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM