清除透明的BufferedImage尽可能快 [英] Clear a transparent BufferedImage as fast as possible
本文介绍了清除透明的BufferedImage尽可能快的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下code(不相关的它是如何创建的,我认为)创建了一个透明的BufferedImage:
I have a transparent BufferedImage created with the following code(not relevant how it is created, I think):
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice gs = ge.getDefaultScreenDevice();
GraphicsConfiguration gc = gs.getDefaultConfiguration();
Rectangle screen = transformationContext.getScreen();
// Create an image that supports transparent pixels
return gc.createCompatibleImage((int) screen.getWidth(), (int) screen.getHeight(),
Transparency.BITMASK);
我如何清除图像(在相同的状态空图像,因为它创建)最快可能的方式不重新创建的形象呢?重塑形象穿GC的负担,暂停虚拟机并冻结UI。
How do I clear the image(empty image in the same state as it was created) in the fastest way possible without recreating the image? Recreating the image puts a burden on GC, pausing the VM and freezing the UI.
推荐答案
明白了:)使用clearRect代替填充透明色。
Got it :) used clearRect instead of fill with a transparent color.
graphics = (Graphics2D) offlineBuffer.getGraphics();
graphics.setBackground(new Color(255, 255, 255, 0));
Rectangle screen = transformationContext.getScreen();
graphics.clearRect(0,0, (int)screen.getWidth(), (int)screen.getHeight());
这篇关于清除透明的BufferedImage尽可能快的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文