S
steve
Hi,
I have a graphic image that i want to display and show in a scroll window.
however currently when the user re-scales the graphic , it is only showing
the top left corner.
not having done much graphical manipulation, I'm lost.
I suspect it is because , my canvas is only the size of my onscreen scroll
area, how can i easily fix it?
or is it the use of the Canvas that is breaking it?
(MyCanvas is sitting inside a scrollpane as in
private MyCanvas SplashImageLabel = new MyCanvas();
jScrollPane1.getViewport().add(SplashImageLabel, null);
class MyCanvas extends Canvas {
private BufferedImage TheImage;
float aa;
public MyCanvas() {
super();
}
public void setImage(BufferedImage i,String Scale) {
TheImage = i;
aa=Integer.parseInt(Scale);
repaint();
}
public void paint(Graphics g) {
Graphics2D g2D = (Graphics2D) g;
if (TheImage != null)
if (aa<min) { aa=min;}
if (aa>max) { aa=max;}
int thumbWidth = (int)
(TheImage.getWidth()*(aa/100));
int thumbHeight = (int)
(TheImage.getHeight()*(aa/100));
// BufferedImage thumbImage = new BufferedImage(
// thumbWidth, thumbHeight,
BufferedImage.TYPE_INT_RGB);
// Graphics2D g2D= thumbImage.createGraphics();
g2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION,RenderingHints.VA
LUE_INTERPOLATION_BILINEAR);
g2D.drawImage(TheImage, 0, 0, thumbWidth, thumbHeight,
null);
}
}
I have a graphic image that i want to display and show in a scroll window.
however currently when the user re-scales the graphic , it is only showing
the top left corner.
not having done much graphical manipulation, I'm lost.
I suspect it is because , my canvas is only the size of my onscreen scroll
area, how can i easily fix it?
or is it the use of the Canvas that is breaking it?
(MyCanvas is sitting inside a scrollpane as in
private MyCanvas SplashImageLabel = new MyCanvas();
jScrollPane1.getViewport().add(SplashImageLabel, null);
class MyCanvas extends Canvas {
private BufferedImage TheImage;
float aa;
public MyCanvas() {
super();
}
public void setImage(BufferedImage i,String Scale) {
TheImage = i;
aa=Integer.parseInt(Scale);
repaint();
}
public void paint(Graphics g) {
Graphics2D g2D = (Graphics2D) g;
if (TheImage != null)
if (aa<min) { aa=min;}
if (aa>max) { aa=max;}
int thumbWidth = (int)
(TheImage.getWidth()*(aa/100));
int thumbHeight = (int)
(TheImage.getHeight()*(aa/100));
// BufferedImage thumbImage = new BufferedImage(
// thumbWidth, thumbHeight,
BufferedImage.TYPE_INT_RGB);
// Graphics2D g2D= thumbImage.createGraphics();
g2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION,RenderingHints.VA
LUE_INTERPOLATION_BILINEAR);
g2D.drawImage(TheImage, 0, 0, thumbWidth, thumbHeight,
null);
}
}