public void zoomIn() {
if (ratio < 3200) {
ratio *= 2;
Dimension dim = new Dimension(image.getWidth(this) * ratio / 100, image.getHeight(this) * ratio / 100);
setPreferredSize(dim);
setSize(dim);
}
}
public void zoomOut() {
if (ratio > 1) {
ratio /= 2;
Dimension dim = new Dimension(image.getWidth(this) * ratio / 100, image.getHeight(this) * ratio / 100);
setPreferredSize(dim);
setSize(dim);
}
}
@Override
public void paint(Graphics g) {
Dimension dim = getPreferredSize();
g.drawImage(image, 0, 0, dim.width, dim.height, this);
}
@Override
public boolean imageUpdate(Image img, int infoflags, int x, int y, int w, int h) {
if ((ALLBITS & infoflags) != 0) {
// 読み込み終わり
// PanelのサイズとImageのサイズに制限する(setPreferredSizeを設定しないとScrollバーが正常に表示されません)
setPreferredSize(new Dimension(image.getWidth(this), image.getHeight(this)));
}
return super.imageUpdate(img, infoflags, x, y, w, h);
}
}
}