graphics display /scroll

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);


}
}
 
O

Oliver Wong

steve said:
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:)

It's been a while since I've done this, but I vaguely recall the trick
is to just paint the whole image onto the canvas, without worry about how
the image is scrolled. The ScrollPane will take care of displacing your
image.

Some of the paint methods provide, as part of the argument, a rectangle
indicating the area that needs to be repainted. The ScrollPane uses this to
allow you to use the optimization of not painting parts of the image which
will not be visible. But again, you don't have to worry about translating
your coordinate system or anything like that, as the ScrollPane will take
care of it.

- Oliver
 
D

ducnbyu

I'm not sure I understand the problem you are describing, but there is
another (overloaded) drawImage method.

public abstract boolean drawImage(Image img,
AffineTransform xform,
ImageObserver obs).

Have you tried this? If you apply a transform to your image you might
be able to control scaling. I work in SWT which has a simpler method,
but have noticed the above method when comparing SWT's GC to AWT's
Graphics2D.
 
S

steve

It's been a while since I've done this, but I vaguely recall the trick
is to just paint the whole image onto the canvas, without worry about how
the image is scrolled. The ScrollPane will take care of displacing your
image.

Some of the paint methods provide, as part of the argument, a rectangle
indicating the area that needs to be repainted. The ScrollPane uses this to
allow you to use the optimization of not painting parts of the image which
will not be visible. But again, you don't have to worry about translating
your coordinate system or anything like that, as the ScrollPane will take
care of it.

- Oliver

it does not work, all i get is the image to the size of the scroll pane, if
i scale the image up, then i just get a section of the image.


Steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top