Greetings,
Stolen from a google search (that found Sun's Java Forums), what if
you did this:
static BufferedImage convertImage(BufferedImage image) {
BufferedImage newImage = new BufferedImage(image.getWidth(),
image.getHeight(),
BufferedImage.TYPE_3BYTE_BGR);
Graphics2D g = newImage.createGraphics();
g.drawRenderedImage(image, null);
g.dispose();
return newImage;
}
and then got the pixels from the new image?
It should allow you to reuse the original, without any issues, and
theoretically the draw here should be very fast.
I don't know that it will work, but it's a thought.
-- Morgan
On 6/30/05, email@hidden <email@hidden> wrote:
> I've already reported this as a bug, but I'm looking for a workaround.
>
> Running under tiger (10.4.1), if you use any one of the three methods shows
> in the sample below to grab pixels from a BufferedImage, then do a
> getGraphics and draw to the same BufferedImage, the drawing speed drops off
> by a factor of 500! In the sample shown, running on a 1.5GHz G4, it takes
> 0.044 seconds to draw 480 lines. After using any one of the methods to grab
> pixels, it takes about 22 seconds to draw the same sequence of lines. Under
> 10.3, 10.2 or Windows, the times are still about 0.044 seconds.
>
> Does anyone know of a way to grab pixels from a BufferedImage under Tiger
> without causing this slowdown? Is there some way to reset the image after
> grabbing pixels to get the original speed back?
>
> Thanks,
> Mike Westerfield
>
> --- sample program ---
>
> package test;
>
> import java.awt.*;
> import java.awt.image.*;
>
> public class Application1 {
> public Application1() {
> try {
> BufferedImage image = new BufferedImage(640, 480,
> BufferedImage.TYPE_INT_ARGB);
> Graphics g = image.getGraphics();
> int[] pixels = new int[40*40];
>
> long time = System.currentTimeMillis();
> for (int i = 0; i < 480; ++i)
> g.drawLine(0, i, 640, i);
> System.out.println("Time before grabbing pixels: " +
> (System.currentTimeMillis() - time)/1000.0);
>
> BufferedImage subimage = image.getSubimage(100, 80, 40, 40);
> image.getRGB(0, 0, 40, 40, pixels, 0, 40);
>
> time = System.currentTimeMillis();
> for (int i = 0; i < 480; ++i)
> g.drawLine(0, i, 640, i);
> System.out.println("Time after getSubimage: " +
> (System.currentTimeMillis() - time)/1000.0);
>
> image.getRGB(100, 80, 40, 40, pixels, 0, 40);
>
> time = System.currentTimeMillis();
> for (int i = 0; i < 480; ++i)
> g.drawLine(0, i, 640, i);
> System.out.println("Time after getRGB: " +
> (System.currentTimeMillis() - time)/1000.0);
>
> PixelGrabber grabber = new PixelGrabber(image, 100, 80, 40,
> 40, pixels, 0, 40);
> grabber.grabPixels();
>
> time = System.currentTimeMillis();
> for (int i = 0; i < 480; ++i)
> g.drawLine(0, i, 640, i);
> System.out.println("Time after grabbing pixels: " +
> (System.currentTimeMillis() - time)/1000.0);
>
> } catch (Throwable t) {
> t.printStackTrace();
> }
> }
>
> static public void main(String[] args) {
> new Application1();
> }
>
> }
>
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Java-dev mailing list (email@hidden)
> Help/Unsubscribe/Update your Subscription:
> http://lists.apple.com/mailman/options/java-dev/email@hidden
>
> This email sent to email@hidden
>
>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Java-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/java-dev/email@hidden
This email sent to email@hidden