Article View: borland.public.jbuilder.java.api
Article #1174Re: Image pixel inspection (final answer)
From: James Hughes
Date: Thu, 18 Apr 2002 14:11
Date: Thu, 18 Apr 2002 14:11
73 lines
3345 bytes
3345 bytes
I have now got it to work using the PixelGrabber class as follows:
// initialise the Image object
Image gif = Toolkit.getDefaultToolkit().createImage(imageData);
// initialise a pixel grabber
PixelGrabber pg = new PixelGrabber(gif, 0, 0, gif.getWidth(null),
gif.getHeight(null), true);
// grab the pixels
try
{
pg.grabPixels();
}
catch(InterruptedException ie)
{
ie.printStackTrace();
throw new GifReaderException("PixelGrabber was interrupted while
reading from GIF Image bytes");
}
// retrieve the pixels from the grabber
int[] pixels = (int[])pg.getPixels();
And now the pixels array contains RGB data, which I can inspect to my
heart's conent :) I still dont quite understand the way the image loading
works, but there's no rush to find out anymore either.
"James Hughes" <jimbogaz@hotmail.com> wrote in message
news:3cbec8d4_1@dnews...
> Ok, here is what I have now:
>
> // initialise the Image object
> Image gif = Toolkit.getDefaultToolkit().createImage(imageData);
>
> // have to draw the image to find it's size
> BufferedImage buff = new BufferedImage(20, 20,
> BufferedImage.TYPE_INT_ARGB);
> boolean imageReady = buff.getGraphics().drawImage(gif,0, 0, null);
>
> Now, the imageReady has a value of 'false', which means that for some
reason
> the image is not loaded - why? Also, this means that buff.getRGB(x, y)
does
> not retrieve the correct values for the pixels - how can I get around
this?
> Is there a way of forcing the image to load, and if not, can anybody tell
me
> why not?
>
> Thanks in advance,
> J
>
> "John McGrath [TeamB]" <ng-b@JPMcGrath.net> wrote in message
> news:MPG.172792c58476aca498b544@newsgroups.borland.com...
> > On Wed, 17 Apr 2002 09:04:44 +0100, James Hughes wrote:
> >
> > > I have got as far as loading the Image into a BufferedImage,
> > > but I dont know how to get at the pixels, can anybody help me?
> >
> > int rgb = bufferedImage.getRGB( x, y );
> >
> > --
> > Regards,
> >
> > John McGrath [TeamB]
> >
> > ---------------------------------------------------
> > Before sending me e-mail, please read:
> > http://www.JPMcGrath.net/newsgroups/e-mail.html
>
>
Technical Details
Message-ID:
<3cbed481$1_1@dnews>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-03!supernews.com!newsswitch.lcs.mit.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!nntp.abs.net!uunet!dca.uu.net!newsfeeds.ihug.co.nz!ihug.co.nz!dnewsReferences:
<3cbd2d36$1_1@dnews> <MPG.172792c58476aca498b544@newsgroups.borland.com> <3cbec8d4_1@dnews>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 1089d0,937c9cd9161d2c82 X-Google-Attributes: gid1089d0,public X-Google-ArrivalTime: 2002-04-18 07:22:03 PST Reply-To: "James Hughes" <jimbogaz@hotmail.com> From: "James Hughes" <jimbogaz@hotmail.com> Newsgroups: borland.public.jbuilder.java.api References: <3cbd2d36$1_1@dnews> <MPG.172792c58476aca498b544@newsgroups.borland.com> <3cbec8d4_1@dnews> Subject: Re: Image pixel inspection (final answer) Date: Thu, 18 Apr 2002 15:11:27 +0100 Lines: 75 Organization: Avoca Communications 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: 212.161.14.102 Message-ID: <3cbed481$1_1@dnews> X-Trace: dnews 1019139201 212.161.14.102 (18 Apr 2002 07:13:21 -0700) Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-03!supernews.com!newsswitch.lcs.mit.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!nntp.abs.net!uunet!dca.uu.net!newsfeeds.ihug.co.nz!ihug.co.nz!dnews