0
public class ImagePreview extends JPanel {
private static final long serialVersionUID = 1L;
final float ratio = 1.0f;
private RenderedImage image;
public ImagePreview (int imgWidth, int imgHeight) {
this.setPreferredSize(new Dimension((int) (ratio * imgWidth) + 5, (int) (ratio * imgHeight) + 5));
}
public ImagePreview (int imgWidth, int imgHeight, final RenderedImage image) {
super();
this.setPreferredSize(new Dimension((int) (ratio * imgWidth) + 5, (int) (ratio * imgHeight) + 5));
this.image = image;
repaint();
}
@Override
public synchronized void paintComponent(Graphics g) {
super.paintComponent(g);
VectorGraphics g2 = VectorGraphics.create(g);
if (image != null) {
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2.drawRenderedImage(image, AffineTransform.getScaleInstance(ratio, ratio));
}
}
}
調用此方法上的一個按鈕點擊 //調用此方法 ImagePreview購物=新ImagePreview(imgWidth,imgHeight,圖像);問題用的paintComponent()
我得到的圖像,但它沒有得到重新在面板上重繪。我無法在確定後面那個
你正在使用VectorGraphics哪個第三方框架是這樣的?或者這是你的代碼? –
是的,這是我的代碼,我正在使用import org.freehep.graphics2d.VectorGraphics; libary – user3507196
您正在將RenderedImage傳遞給構造函數,可以顯示它是如何加載的? – Kuba