Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Drawing to BufferedImage slows down after grabbing pixels



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



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.