Edward,

The BufferedImage object in Java2D was created for easier access to the
pixels of an image, so I think you might find it easier to use that
API for what you are doing rather than the ImageProducer approach.
To get the array of pixel data from a BufferedImage, you could do
something like:
                // createImage(w,h) doesn't guarantee a BufferedImage
                // but it works that way for now.  There are other
                // ways to create a BufferedImage directly, but this
                // will do for this example
        BufferedImage bImg = (BufferedImage)createImage(w, h);
        Raster raster = bImg.getRaster();
        DataBuffer dBuff = raster.getDataBuffer();
(I'm glossing over some of the details here, but these are the
main objects that you would play with to set pixel data).

Having said this, if your interest is in gaming and fast graphics,
you might try to find a way to avoid playing with the pixels directly;
if you could use higher-level API to set your pixel data that would
be easier for the API to accelerate.  For example, if you need
to draw a line, it would be better to call bImg.getGraphics().drawLine()
than to draw that line yourself (no matter how fast your line-drawing
algorithm is).  This is somewhat true for the current jdk release,
but will be even more the case going forward.
As of the next release (jdk1.4), we are enabling the use of hardware
acceleration for offscreen images.  But if you request access to the
pixel data directly, we have to punt and disable acceleration for
that image.

I hope this helps.

Chet.

> X-Accept-Language: en
> Content-Transfer-Encoding: 7bit
> From: Edvard Fagerholm <[EMAIL PROTECTED]>
> Subject: [JAVA2D] ImageProducers
> To: [EMAIL PROTECTED]
>
> As I haven't got any reponse, in the gamedev.net forums, I'm going to
> paste my question here.
>
> -------
> This is maybe a stupid question, but I don't feel like using my whole
> day digging the Java2D API refernce. So what's the fastest and simplest
> way to turn an Image into an ImageProducer, so that I could manipulate
> myself.
>
> The problem is that some of the images are changing, and I have to turn
> Images into inta rrays or something very quickly. Is there any way to
> simply make your array point directly to the image object so that I
> could quickly write pixels into it, or do I have to make a copy of an
> Image pixel by pixel into an array. Doing this would produce extra I/O,
> and that would hurt performance seriously.
>
> I haven't really been doing any extensive graphics programming in java,
> I've been doing everything relating to graphics in C & asm, so if
> someone could help me I'd appreciate it.
>
> Thanks in advance
> Edvard Fagerholm
>
> ===========================================================================
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
> of the message "signoff JAVA2D-INTEREST".  For general help, send email to
> [EMAIL PROTECTED] and include in the body of the message "help".

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to