Article View: borland.public.jbuilder.java.api
Article #1167Re: how do I draw a JPG to a panel/container
From: PeterH
Date: Thu, 18 Apr 2002 00:38
Date: Thu, 18 Apr 2002 00:38
56 lines
3243 bytes
3243 bytes
Thank you Gillmer. This worked just great! :> I still have to play around with the MediaTracker, but I got it to load and dynamically resize (something I had to code hoops around in VB! :>). I've been hearing things about doing things with a double buffer instead of in memory, or objects that are directly being used to display on the screen. Could you point me in the right direction to start finding information on? Much appreciated. Thanks again! :> "Gillmer J. Derge [TeamB]" <spam@gillmerderge.com> wrote in message news:3cbcf62f_1@dnews... > "PeterH" <!Sorry-TooMuchSpam!nope@nope.com> wrote in message > news:3cbcdf8a_1@dnews... > > I've typed in the following code (easy on the code review, I'm playing > with > > things :>). And I was able to get things to load up without the code for > > the scaledImage. I was trying to scale the image to the current frame > size. > > I saw the Image.getScaledInstance() and thought that would do it, but now > I > > can't see anything on the screen (no picture I mean). If I take a look a > > the width method, it says -1, so that would lead me to believe the image > > hasn't loaded or has an error. What do you think? > > Images are strange, because you get back an object immediately, but they > load in the background. So just because you got back a result from > getScaledInstance doesn't mean it has finished loading yet. > > Before you draw it, you should make sure it has loaded. The best way to do > that is with a MediaTracker. Something like this will work. > > MediaTracker tracker = new MediaTracker(this); > tracker.addImage(scaledImage, 0); > tracker.waitForAll(); > > Once you get this working, you should probably only get a new scaled > instance when the frame's size changes and keep it cached so you can > repaint with the same image object each time. Otherwise every time your > component needs to repaint, you'll be waiting for the image to be processed > which will introduce some sluggishness in the response. > > -- > Gillmer J. Derge [TeamB] > > >
Technical Details
Message-ID:
<3cbe170c$1_2@dnews>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-03!supernews.com!peer1-sjc1.usenetserver.com!usenetserver.com!hub1.nntpserver.com!xmission!news-out.spamkiller.net!propagator2-maxim!propagator-maxim!news-in.spamkiller.net!news02.tsnz.net!newsfeed01.tsnz.net!newsfeeds.ihug.co.nz!ihug.co.nz!dnewsReferences:
<3cb9ef73$1_1@dnews> <MPG.172579c5bd0dc2ea98b534@newsgroups.borland.com> <3cbc80fd$1_2@dnews> <3cbc9afb_2@dnews> <3cbcdf8a_1@dnews> <3cbcf62f_1@dnews>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 1089d0,422c9cef40be2392 X-Google-Attributes: gid1089d0,public X-Google-ArrivalTime: 2002-04-17 18:01:21 PST From: "PeterH" <!Sorry-TooMuchSpam!nope@nope.com> Newsgroups: borland.public.jbuilder.java.api References: <3cb9ef73$1_1@dnews> <MPG.172579c5bd0dc2ea98b534@newsgroups.borland.com> <3cbc80fd$1_2@dnews> <3cbc9afb_2@dnews> <3cbcdf8a_1@dnews> <3cbcf62f_1@dnews> Subject: Re: how do I draw a JPG to a panel/container Date: Wed, 17 Apr 2002 20:38:04 -0400 Lines: 58 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2600.0000 X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 NNTP-Posting-Host: 24.112.10.56 Message-ID: <3cbe170c$1_2@dnews> X-Trace: dnews 1019090700 24.112.10.56 (17 Apr 2002 17:45:00 -0700) Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-03!supernews.com!peer1-sjc1.usenetserver.com!usenetserver.com!hub1.nntpserver.com!xmission!news-out.spamkiller.net!propagator2-maxim!propagator-maxim!news-in.spamkiller.net!news02.tsnz.net!newsfeed01.tsnz.net!newsfeeds.ihug.co.nz!ihug.co.nz!dnews