如何减少图像放大和缩小的开销。
这是我的代码,放大/缩小图像需要很长时间......
@Override
public void mouseWheelMoved(MouseWheelEvent e) {
int myX = 0;
int myY = 0;
if (e.getScrollType() == MouseWheelEvent.WHEEL_UNIT_SCROLL) {
try {
float amount = e.getWheelRotation() * 5f;
myX = (int) (label.getWidth() + amount);
myY = (int) (label.getHeight() + amount);
imgX = myX;
imgY = myY;
label.setSize(myX, myY);
scalledItemImage = itemImage.getScaledInstance(imgX, imgY,
BufferedImage.TYPE_INT_ARGB);
ImageIcon icon = new ImageIcon(scalledItemImage);
label.setIcon(icon);
repaint();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
如何使用预期的分辨率和图像清晰度加速图像渲染。
答案 0 :(得分:2)
你以错误的方式调用scale方法....
尝试致电:
scalledItemImage = itemImage.getScaledInstance(imgX, imgY,
BufferedImage.SCALE_FAST);
(如上所述)