Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / January 2005

Tip: Looking for answers? Try searching our database.

newbie question about image loading

Thread view: 
Di Pascale - 24 Jan 2005 13:00 GMT
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.
Thomas Weidenfeller - 24 Jan 2005 13:42 GMT
> 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.

http://java.sun.com/j2se/1.5.0/docs/api/java/awt/Graphics.html#drawImage(java.aw
t.Image,%20int,%20int,%20int,%20int,%20int,%20int,%20int,%20int,%20java.awt.imag
e.ImageObserver
)

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

http://java.sun.com/j2se/1.5.0/docs/api/java/awt/image/BufferedImage.html#getSub
image(int,%20int,%20int,%20int
)

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
Signature

The comp.lang.java.gui FAQ:
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq

Di Pascale - 24 Jan 2005 17:54 GMT
You've been of great help... thanks a lot!!! I'll try to get the hang of
all the possibilities you've illustrated.

>> 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
[quoted text clipped - 23 lines]
>
> /Thomas


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.