Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Caching and preallocating images by ThreadLocal #100

Open
eix128 opened this issue Mar 10, 2014 · 0 comments
Open

Caching and preallocating images by ThreadLocal #100

eix128 opened this issue Mar 10, 2014 · 0 comments

Comments

@eix128
Copy link

eix128 commented Mar 10, 2014

Hello , i checked your source codes and you always make new BufferedImage per scale.
This is time consuming.You can pre allocate images by ThreadLocal like shown below example :

    final BufferedImage screenCapture = robot.createScreenCapture( new Rectangle( 0 , 0 , 1 , 1));
    imageThreadLocal = new ThreadLocal<BufferedImage>() {
        @Override
        protected BufferedImage initialValue() {
            final RectangleEx rectangle1 = rootRects[0];
            final Rectangle rectangle2 = rectangle1.getRectangle();
            return new BufferedImage(  rectangle2.width , rectangle2.height , screenCapture.getType() );
        }
    };



writer = new ThreadLocal<ImageWriter>() {
        @Override
        protected ImageWriter initialValue() {
            final Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("jpg");
            if (!writers.hasNext())
                throw new IllegalStateException("No writers found");
            ImageWriter writer2  = (ImageWriter) writers.next();
            return writer2;
        }
    };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant