下面列出了java.awt.image.BufferedImage#setAccelerationPriority() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private static BufferedImage makeUnmanagedBI(final int type) {
final BufferedImage bi = new BufferedImage(511, 255, type);
final DataBuffer db = bi.getRaster().getDataBuffer();
if (db instanceof DataBufferInt) {
((DataBufferInt) db).getData();
} else if (db instanceof DataBufferShort) {
((DataBufferShort) db).getData();
} else if (db instanceof DataBufferByte) {
((DataBufferByte) db).getData();
} else {
try {
bi.setAccelerationPriority(0.0f);
} catch (final Throwable ignored) {
}
}
return bi;
}
private static BufferedImage makeUnmanagedBI(final int type) {
final BufferedImage img = new BufferedImage(SIZE, SIZE, type);
final DataBuffer db = img.getRaster().getDataBuffer();
if (db instanceof DataBufferInt) {
((DataBufferInt) db).getData();
} else if (db instanceof DataBufferShort) {
((DataBufferShort) db).getData();
} else if (db instanceof DataBufferByte) {
((DataBufferByte) db).getData();
} else {
try {
img.setAccelerationPriority(0.0f);
} catch (final Throwable ignored) {
}
}
return img;
}
private static BufferedImage makeUnmanagedBI(GraphicsConfiguration gc,
int type) {
BufferedImage img = gc.createCompatibleImage(SIZE, SIZE, type);
Graphics2D g2d = img.createGraphics();
g2d.setColor(RGB);
g2d.fillRect(0, 0, SIZE, SIZE);
g2d.dispose();
final DataBuffer db = img.getRaster().getDataBuffer();
if (db instanceof DataBufferInt) {
((DataBufferInt) db).getData();
} else if (db instanceof DataBufferShort) {
((DataBufferShort) db).getData();
} else if (db instanceof DataBufferByte) {
((DataBufferByte) db).getData();
} else {
try {
img.setAccelerationPriority(0.0f);
} catch (final Throwable ignored) {
}
}
return img;
}
private static BufferedImage makeUnmanagedBI(final int type) {
final BufferedImage img = new BufferedImage(SIZE, SIZE, type);
final DataBuffer db = img.getRaster().getDataBuffer();
if (db instanceof DataBufferInt) {
((DataBufferInt) db).getData();
} else if (db instanceof DataBufferShort) {
((DataBufferShort) db).getData();
} else if (db instanceof DataBufferByte) {
((DataBufferByte) db).getData();
} else {
try {
img.setAccelerationPriority(0.0f);
} catch (final Throwable ignored) {
}
}
return img;
}
private static BufferedImage getBufferedImage(int sw) {
final BufferedImage bi = new BufferedImage(sw, sw, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2d = bi.createGraphics();
g2d.setColor(Color.RED);
g2d.fillRect(0, 0, sw, sw);
g2d.dispose();
final DataBuffer db = bi.getRaster().getDataBuffer();
if (db instanceof DataBufferInt) {
((DataBufferInt) db).getData();
} else if (db instanceof DataBufferShort) {
((DataBufferShort) db).getData();
} else if (db instanceof DataBufferByte) {
((DataBufferByte) db).getData();
} else {
try {
bi.setAccelerationPriority(0.0f);
} catch (final Throwable ignored) {
}
}
return bi;
}
private static BufferedImage makeUnmanagedBI(final int type) {
final BufferedImage bi = new BufferedImage(511, 255, type);
final DataBuffer db = bi.getRaster().getDataBuffer();
if (db instanceof DataBufferInt) {
((DataBufferInt) db).getData();
} else if (db instanceof DataBufferShort) {
((DataBufferShort) db).getData();
} else if (db instanceof DataBufferByte) {
((DataBufferByte) db).getData();
} else {
try {
bi.setAccelerationPriority(0.0f);
} catch (final Throwable ignored) {
}
}
return bi;
}
public Image makeImage(TestEnvironment env, int w, int h) {
BufferedImage img = new BufferedImage(w, h, type);
if (unmanaged) {
DataBuffer db = img.getRaster().getDataBuffer();
if (db instanceof DataBufferInt) {
((DataBufferInt)db).getData();
} else if (db instanceof DataBufferShort) {
((DataBufferShort)db).getData();
} else if (db instanceof DataBufferByte) {
((DataBufferByte)db).getData();
} else {
try {
img.setAccelerationPriority(0.0f);
} catch (Throwable e) {}
}
}
return img;
}
/**
* Return a non-accelerated BufferedImage of the requested type with the
* indicated subimage of the original image located at 0,0 in the new image.
* If a bgColor is supplied, composite the original image over that color
* with a SrcOver operation, otherwise make a SrcNoEa copy.
* <p>
* Returned BufferedImage is not accelerated for two reasons:
* <ul>
* <li> Types of the image and surface are predefined, because these types
* correspond to the TransformHelpers, which we know we have. And
* acceleration can change the type of the surface
* <li> Image will be used only once and acceleration caching wouldn't help
* </ul>
*/
BufferedImage makeBufferedImage(Image img, Color bgColor, int type,
int sx1, int sy1, int sx2, int sy2)
{
final int width = sx2 - sx1;
final int height = sy2 - sy1;
final BufferedImage bimg = new BufferedImage(width, height, type);
final SunGraphics2D g2d = (SunGraphics2D) bimg.createGraphics();
g2d.setComposite(AlphaComposite.Src);
bimg.setAccelerationPriority(0);
if (bgColor != null) {
g2d.setColor(bgColor);
g2d.fillRect(0, 0, width, height);
g2d.setComposite(AlphaComposite.SrcOver);
}
g2d.copyImage(img, 0, 0, sx1, sy1, width, height, null, null);
g2d.dispose();
return bimg;
}
public Image makeImage(TestEnvironment env, int w, int h) {
BufferedImage img = new BufferedImage(w, h, type);
if (unmanaged) {
DataBuffer db = img.getRaster().getDataBuffer();
if (db instanceof DataBufferInt) {
((DataBufferInt)db).getData();
} else if (db instanceof DataBufferShort) {
((DataBufferShort)db).getData();
} else if (db instanceof DataBufferByte) {
((DataBufferByte)db).getData();
} else {
try {
img.setAccelerationPriority(0.0f);
} catch (Throwable e) {}
}
}
return img;
}
public Image makeImage(TestEnvironment env, int w, int h) {
BufferedImage img = new BufferedImage(w, h, type);
if (unmanaged) {
DataBuffer db = img.getRaster().getDataBuffer();
if (db instanceof DataBufferInt) {
((DataBufferInt)db).getData();
} else if (db instanceof DataBufferShort) {
((DataBufferShort)db).getData();
} else if (db instanceof DataBufferByte) {
((DataBufferByte)db).getData();
} else {
try {
img.setAccelerationPriority(0.0f);
} catch (Throwable e) {}
}
}
return img;
}
public Image makeImage(TestEnvironment env, int w, int h) {
BufferedImage img = new BufferedImage(w, h, type);
if (unmanaged) {
DataBuffer db = img.getRaster().getDataBuffer();
if (db instanceof DataBufferInt) {
((DataBufferInt)db).getData();
} else if (db instanceof DataBufferShort) {
((DataBufferShort)db).getData();
} else if (db instanceof DataBufferByte) {
((DataBufferByte)db).getData();
} else {
try {
img.setAccelerationPriority(0.0f);
} catch (Throwable e) {}
}
}
return img;
}
private static BufferedImage makeUnmanagedBI(GraphicsConfiguration gc,
int type) {
BufferedImage img = gc.createCompatibleImage(SIZE, SIZE, type);
Graphics2D g2d = img.createGraphics();
g2d.setColor(RGB);
g2d.fillRect(0, 0, SIZE, SIZE);
g2d.dispose();
final DataBuffer db = img.getRaster().getDataBuffer();
if (db instanceof DataBufferInt) {
((DataBufferInt) db).getData();
} else if (db instanceof DataBufferShort) {
((DataBufferShort) db).getData();
} else if (db instanceof DataBufferByte) {
((DataBufferByte) db).getData();
} else {
try {
img.setAccelerationPriority(0.0f);
} catch (final Throwable ignored) {
}
}
return img;
}
private static BufferedImage makeUnmanagedBI(GraphicsConfiguration gc,
int type) {
BufferedImage img = gc.createCompatibleImage(SIZE, SIZE, type);
Graphics2D g2d = img.createGraphics();
g2d.setColor(RGB);
g2d.fillRect(0, 0, SIZE, SIZE);
g2d.dispose();
final DataBuffer db = img.getRaster().getDataBuffer();
if (db instanceof DataBufferInt) {
((DataBufferInt) db).getData();
} else if (db instanceof DataBufferShort) {
((DataBufferShort) db).getData();
} else if (db instanceof DataBufferByte) {
((DataBufferByte) db).getData();
} else {
try {
img.setAccelerationPriority(0.0f);
} catch (final Throwable ignored) {
}
}
return img;
}
static Image getBufferedImage(GraphicsConfiguration gc,
int w, int h, int type, boolean acceleratable)
{
BufferedImage image = new BufferedImage(w, h, type);
if (!acceleratable) {
image.setAccelerationPriority(0.0f);
}
initImage(gc, image);
return image;
}
static Image getBufferedImage(GraphicsConfiguration gc,
int w, int h, int type, boolean acceleratable)
{
BufferedImage image = new BufferedImage(w, h, type);
if (!acceleratable) {
image.setAccelerationPriority(0.0f);
}
initImage(gc, image);
return image;
}
/**
* Returns the BufferedImage that will be used as the representation of
* the pixel data. Subclasses can override this method to return
* platform specific subclasses of BufferedImage that may or may not be
* accelerated.
*
* It is subclass' responsibility to propagate acceleration priority
* to the newly created image.
*/
protected BufferedImage createImage(ColorModel cm,
WritableRaster raster,
boolean isRasterPremultiplied,
Hashtable properties)
{
BufferedImage bi =
new BufferedImage(cm, raster, isRasterPremultiplied, null);
bi.setAccelerationPriority(image.getAccelerationPriority());
return bi;
}
/**
* Returns the BufferedImage that will be used as the representation of
* the pixel data. Subclasses can override this method to return
* platform specific subclasses of BufferedImage that may or may not be
* accelerated.
*
* It is subclass' responsibility to propagate acceleration priority
* to the newly created image.
*/
protected BufferedImage createImage(ColorModel cm,
WritableRaster raster,
boolean isRasterPremultiplied,
Hashtable properties)
{
BufferedImage bi =
new BufferedImage(cm, raster, isRasterPremultiplied, null);
bi.setAccelerationPriority(image.getAccelerationPriority());
return bi;
}
/**
* Returns the BufferedImage that will be used as the representation of
* the pixel data. Subclasses can override this method to return
* platform specific subclasses of BufferedImage that may or may not be
* accelerated.
*
* It is subclass' responsibility to propagate acceleration priority
* to the newly created image.
*/
protected BufferedImage createImage(ColorModel cm,
WritableRaster raster,
boolean isRasterPremultiplied,
Hashtable<?,?> properties)
{
BufferedImage bi =
new BufferedImage(cm, raster, isRasterPremultiplied, null);
bi.setAccelerationPriority(image.getAccelerationPriority());
return bi;
}
/**
* Returns the BufferedImage that will be used as the representation of
* the pixel data. Subclasses can override this method to return
* platform specific subclasses of BufferedImage that may or may not be
* accelerated.
*
* It is subclass' responsibility to propagate acceleration priority
* to the newly created image.
*/
protected BufferedImage createImage(ColorModel cm,
WritableRaster raster,
boolean isRasterPremultiplied,
Hashtable properties)
{
BufferedImage bi =
new BufferedImage(cm, raster, isRasterPremultiplied, null);
bi.setAccelerationPriority(image.getAccelerationPriority());
return bi;
}
/**
* Returns the BufferedImage that will be used as the representation of
* the pixel data. Subclasses can override this method to return
* platform specific subclasses of BufferedImage that may or may not be
* accelerated.
*
* It is subclass' responsibility to propagate acceleration priority
* to the newly created image.
*/
protected BufferedImage createImage(ColorModel cm,
WritableRaster raster,
boolean isRasterPremultiplied,
Hashtable properties)
{
BufferedImage bi =
new BufferedImage(cm, raster, isRasterPremultiplied, null);
bi.setAccelerationPriority(image.getAccelerationPriority());
return bi;
}