 |
AppletTalk.com Java discussions newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Di Pascale Guest
|
Posted: Mon Jan 24, 2005 1:00 pm Post subject: newbie question about image loading |
|
|
I need to display only a particular portion of a big gif image in a
fixed-size square component; the coordinates of the visible square to
display are to be determined at runtime. What image component should I
use? I am only familair with the Swing label's setIcon() method, but it
doesn't let me choose what part of the image I want to display.
Any help would be greatly appreciated. Thanks in advance.
|
|
| Back to top |
|
 |
Thomas Weidenfeller Guest
|
Posted: Mon Jan 24, 2005 1:42 pm Post subject: Re: newbie question about image loading |
|
|
Di Pascale wrote:
| Quote: | I need to display only a particular portion of a big gif image in a
fixed-size square component; the coordinates of the visible square to
display are to be determined at runtime. What image component should I
use? I am only familair with the Swing label's setIcon() method, but it
doesn't let me choose what part of the image I want to display.
|
a) Use e.g. any subclass of Image, e.g. BufferedImage, to hold the
image, and a JPanel to display it. Use e.g.
[url]http://java.sun.com/j2se/1.5.0/docs/api/java/awt/Graphics.html#drawImage(java.awt.Image,%20int,%20int,%20int,%20int,%20int,%20int,%20int,%20int,%20java.awt.image.ImageObserver[/url])
to draw the image.
In order to pull this successful off, you need to familiarize yourself
with the general way drawing/painting in Swing happens.
b) Load the Image into a BufferedImage. Then use
[url]http://java.sun.com/j2se/1.5.0/docs/api/java/awt/image/BufferedImage.html#getSubimage(int,%20int,%20int,%20int[/url])
to create a sub-image. Create an ImageIcon from the BufferedImage and
display that ImageIcon in a JLabel.
c) Use a scrollpane, turn the scrollbars of, and set the viewport to the
parts of the image you want to display.
/Thomas
--
The comp.lang.java.gui FAQ:
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq
|
|
| Back to top |
|
 |
Di Pascale Guest
|
Posted: Mon Jan 24, 2005 5:54 pm Post subject: Re: newbie question about image loading |
|
|
You've been of great help... thanks a lot!!! I'll try to get the hang of
all the possibilities you've illustrated.
Thomas Weidenfeller wrote:
| Quote: | Di Pascale wrote:
I need to display only a particular portion of a big gif image in a
fixed-size square component; the coordinates of the visible square to
display are to be determined at runtime. What image component should I
use? I am only familair with the Swing label's setIcon() method, but
it doesn't let me choose what part of the image I want to display.
a) Use e.g. any subclass of Image, e.g. BufferedImage, to hold the
image, and a JPanel to display it. Use e.g.
[url]http://java.sun.com/j2se/1.5.0/docs/api/java/awt/Graphics.html#drawImage(java.awt.Image,%20int,%20int,%20int,%20int,%20int,%20int,%20int,%20int,%20java.awt.image.ImageObserver[/url])
to draw the image.
In order to pull this successful off, you need to familiarize yourself
with the general way drawing/painting in Swing happens.
b) Load the Image into a BufferedImage. Then use
[url]http://java.sun.com/j2se/1.5.0/docs/api/java/awt/image/BufferedImage.html#getSubimage(int,%20int,%20int,%20int[/url])
to create a sub-image. Create an ImageIcon from the BufferedImage and
display that ImageIcon in a JLabel.
c) Use a scrollpane, turn the scrollbars of, and set the viewport to the
parts of the image you want to display.
/Thomas
|
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|