Hi Danny, it looks like we're missing an optimized software loop for scaling binary images. We had to pick the loops we want to have optimized, and I guess this one hasn't been chosen.
My suggestion is to pre-scale your image once (per scale change), and then show the cached scaled version in the scroll pane. The tradeoff will be more memory requred to keep the scaled version around. Thank you, Dmitri On Thu, Oct 16, 2003 at 02:29:21PM -0600, Danny Manners wrote: > (J2SE 1.4.1 under Windows 2000 Professional) > > In an image editing application, I'm obtaining an Image from a scanner > using the JavaTwain package, and creating a BufferedImage from it as > follows: > > Image image; > BufferedImage bimage; > float scale; > . . . > // get image from scanner > . . . > BufferedImage bimage = new BufferedImage( > image.getWidth(null), > image.getHeight(null), > BufferedImage.TYPE_BYTE_GRAY); > Graphics2D g2d = bimage.createGraphics(); > g2d.drawImage(image, 0, 0, null); > > The BufferedImage is passed to a custom component (subclass of JPanel) > which is displayed within a JScrollPane. The image can be scaled which is > done with the following in the custom component's paintComponent(): > > public synchronized void paintComponent(Graphics g) { > Graphics2D g2d = (Graphics2D) g; > g2d.scale(scale, scale); > . . > g2d.drawImage(bimage, 0, 0, null); > > All very obvious. Now, performance when scrolling large images is fine with > TYPE_BYTE_GRAY. It doesn't make any difference whether I tell the scanner > to pass me a colour, grayscale, or black-and-white image. (Presumably it's > a once-only conversion in the BufferedImage constructor). > > However, I'd like to work in black-and-white - the images I'm dealing with > are mainly text and are usually clearer that way. If I change the > BufferedImage type to TYPE_BYTE_BINARY, however, scrolling performance > degrades horribly unless no scaling is done. (More precisely, if the scale > field is set to 1.) Obviously a lot of work is being done with each > repaint, but I don't know what. Again, it makes not difference even if I > request a black-and-white image from the scanner. > > Any help will be appreciated. > > =========================================================================== > 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".