本文整理匯總了Java中java.awt.GraphicsConfiguration.createCompatibleImage方法的典型用法代碼示例。如果您正苦於以下問題:Java GraphicsConfiguration.createCompatibleImage方法的具體用法?Java GraphicsConfiguration.createCompatibleImage怎麽用?Java GraphicsConfiguration.createCompatibleImage使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.awt.GraphicsConfiguration
的用法示例。
在下文中一共展示了GraphicsConfiguration.createCompatibleImage方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: initImages
import java.awt.GraphicsConfiguration; //導入方法依賴的package包/類
private void initImages(int w, int h) {
if (images == null) {
images = new Image[6];
GraphicsConfiguration gc = getGraphicsConfiguration();
for (int i = OPAQUE; i <= TRANSLUCENT; i++) {
VolatileImage vi =
gc.createCompatibleVolatileImage(w,h/images.length,i);
images[i-1] = vi;
vi.validate(gc);
String s = "LCD AA Text rendered to " + tr[i - 1] + " HW destination";
render(vi, i, s);
s = "LCD AA Text rendered to " + tr[i - 1] + " SW destination";
images[i-1+3] = gc.createCompatibleImage(w, h/images.length, i);
render(images[i-1+3], i, s);
}
}
}
示例2: createImageOfTab
import java.awt.GraphicsConfiguration; //導入方法依賴的package包/類
@Override
public Image createImageOfTab(int index) {
TabData td = displayer.getModel().getTab(index);
JLabel lbl = new JLabel(td.getText());
int width = lbl.getFontMetrics(lbl.getFont()).stringWidth(td.getText());
int height = lbl.getFontMetrics(lbl.getFont()).getHeight();
width = width + td.getIcon().getIconWidth() + 6;
height = Math.max(height, td.getIcon().getIconHeight()) + 5;
GraphicsConfiguration config = GraphicsEnvironment.getLocalGraphicsEnvironment()
.getDefaultScreenDevice().getDefaultConfiguration();
BufferedImage image = config.createCompatibleImage(width, height);
Graphics2D g = image.createGraphics();
g.setColor(lbl.getForeground());
g.setFont(lbl.getFont());
td.getIcon().paintIcon(lbl, g, 0, 0);
g.drawString(td.getText(), 18, height / 2);
return image;
}
示例3: createContentImage
import java.awt.GraphicsConfiguration; //導入方法依賴的package包/類
private BufferedImage createContentImage( Component c, Dimension contentSize ) {
GraphicsConfiguration config = GraphicsEnvironment.getLocalGraphicsEnvironment()
.getDefaultScreenDevice().getDefaultConfiguration();
BufferedImage res = config.createCompatibleImage(contentSize.width, contentSize.height);
Graphics2D g = res.createGraphics();
//some components may be non-opaque so just black rectangle would be painted then
g.setColor( Color.white );
g.fillRect(0, 0, contentSize.width, contentSize.height);
if( WinSysPrefs.HANDLER.getBoolean(WinSysPrefs.DND_SMALLWINDOWS, true) && c.getWidth() > 0 && c.getHeight() > 0 ) {
double xScale = contentSize.getWidth() / c.getWidth();
double yScale = contentSize.getHeight() / c.getHeight();
g.setTransform(AffineTransform.getScaleInstance(xScale, yScale) );
}
c.paint(g);
return res;
}
示例4: LevelRenderer
import java.awt.GraphicsConfiguration; //導入方法依賴的package包/類
public LevelRenderer(Level level, GraphicsConfiguration graphicsConfiguration, int width, int height) {
this.width = width;
this.height = height;
this.level = level;
image = graphicsConfiguration.createCompatibleImage(width, height, Transparency.TRANSLUCENT);
g = (Graphics2D) image.getGraphics();
g.setComposite(AlphaComposite.Src);
// //ENABLE PARTIAL TRANSPARENCY FOR LEVEL (AND BACKGROUND?)
// AlphaComposite ac = java.awt.AlphaComposite.getInstance(AlphaComposite.SRC_OVER);
// g.setComposite(ac);
updateArea(0, 0, width, height);
}
示例5: makeUnmanagedBI
import java.awt.GraphicsConfiguration; //導入方法依賴的package包/類
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;
}
示例6: iconToImage
import java.awt.GraphicsConfiguration; //導入方法依賴的package包/類
public static Image iconToImage(Icon icon) {
if (icon instanceof ImageIcon) {
return ((ImageIcon) icon).getImage();
} else {
int w = icon.getIconWidth();
int h = icon.getIconHeight();
GraphicsEnvironment ge
= GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice gd = ge.getDefaultScreenDevice();
GraphicsConfiguration gc = gd.getDefaultConfiguration();
BufferedImage image = gc.createCompatibleImage(w, h);
Graphics2D g = image.createGraphics();
icon.paintIcon(null, g, 0, 0);
g.dispose();
return image;
}
}
示例7: getCompatibleImage
import java.awt.GraphicsConfiguration; //導入方法依賴的package包/類
public static BufferedImage getCompatibleImage(final int width, final int height) {
if (width == 0 && height == 0) {
return null;
}
final GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
final GraphicsDevice device = env.getDefaultScreenDevice();
final GraphicsConfiguration config = device.getDefaultConfiguration();
return config.createCompatibleImage(width, height, Transparency.TRANSLUCENT);
}
示例8: getCompatibleImage
import java.awt.GraphicsConfiguration; //導入方法依賴的package包/類
private static BufferedImage getCompatibleImage(GraphicsConfiguration gc,
int size) {
BufferedImage image = gc.createCompatibleImage(size, size);
Graphics2D g2d = image.createGraphics();
g2d.setColor(Color.GREEN);
g2d.fillRect(0, 0, size, size);
return image;
}
示例9: getTargetGold
import java.awt.GraphicsConfiguration; //導入方法依賴的package包/類
private static BufferedImage getTargetGold(GraphicsConfiguration gc,
int size) {
BufferedImage image = gc.createCompatibleImage(size, size);
Graphics2D g2d = image.createGraphics();
g2d.setColor(Color.GREEN);
g2d.fillRect(0, 0, size, size);
g2d.dispose();
return image;
}
示例10: createDragImage
import java.awt.GraphicsConfiguration; //導入方法依賴的package包/類
/**
* @return An invisible (size 1x1) image to be used for dragging to replace
* the default one supplied by the operating system (if any).
*/
private Image createDragImage() {
GraphicsConfiguration config = GraphicsEnvironment.getLocalGraphicsEnvironment()
.getDefaultScreenDevice().getDefaultConfiguration();
BufferedImage res = config.createCompatibleImage(1, 1);
Graphics2D g = res.createGraphics();
g.setColor( Color.white );
g.fillRect(0,0,1,1);
return res;
}
示例11: createContentImage
import java.awt.GraphicsConfiguration; //導入方法依賴的package包/類
private BufferedImage createContentImage( JComponent c, Dimension contentSize ) {
GraphicsConfiguration cfg = GraphicsEnvironment.getLocalGraphicsEnvironment()
.getDefaultScreenDevice().getDefaultConfiguration();
boolean opaque = c.isOpaque();
c.setOpaque(true);
BufferedImage res = cfg.createCompatibleImage(contentSize.width, contentSize.height);
Graphics2D g = res.createGraphics();
g.setColor( c.getBackground() );
g.fillRect(0, 0, contentSize.width, contentSize.height);
g.setComposite( AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f ));
c.paint(g);
c.setOpaque(opaque);
return res;
}
示例12: test
import java.awt.GraphicsConfiguration; //導入方法依賴的package包/類
private static void test(final BufferedImage bi) throws IOException {
GraphicsEnvironment ge = GraphicsEnvironment
.getLocalGraphicsEnvironment();
GraphicsConfiguration gc = ge.getDefaultScreenDevice()
.getDefaultConfiguration();
VolatileImage vi = gc.createCompatibleVolatileImage(500, 200,
TRANSLUCENT);
BufferedImage gold = gc.createCompatibleImage(500, 200, TRANSLUCENT);
// draw to compatible Image
draw(bi, gold);
// draw to volatile image
int attempt = 0;
BufferedImage snapshot;
while (true) {
if (++attempt > 10) {
throw new RuntimeException("Too many attempts: " + attempt);
}
vi.validate(gc);
if (vi.validate(gc) != VolatileImage.IMAGE_OK) {
continue;
}
draw(bi, vi);
snapshot = vi.getSnapshot();
if (vi.contentsLost()) {
continue;
}
break;
}
// validate images
for (int x = 0; x < gold.getWidth(); ++x) {
for (int y = 0; y < gold.getHeight(); ++y) {
if (gold.getRGB(x, y) != snapshot.getRGB(x, y)) {
ImageIO.write(gold, "png", new File("gold.png"));
ImageIO.write(snapshot, "png", new File("bi.png"));
throw new RuntimeException("Test failed.");
}
}
}
}
示例13: loadSprite
import java.awt.GraphicsConfiguration; //導入方法依賴的package包/類
@Override
public Sprite loadSprite(String ref) {
// otherwise, go away and grab the sprite from the resource
// loader
BufferedImage sourceImage = null;
try {
// The ClassLoader.getResource() ensures we get the sprite
// from the appropriate place, this helps with deploying the game
// with things like webstart. You could equally do a file look
// up here.
URL url = this.getClass().getClassLoader().getResource(ref);
if (url == null) {
fail("Can't find ref: " + ref);
}
// use ImageIO to read the image in
sourceImage = ImageIO.read(url);
} catch (IOException e) {
fail("Failed to load: " + ref);
}
// create an accelerated image of the right size to store our sprite in
GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment()
.getDefaultScreenDevice().getDefaultConfiguration();
Image image = gc.createCompatibleImage(sourceImage.getWidth(), sourceImage.getHeight(),
Transparency.BITMASK);
// draw our source image into the accelerated image
image.getGraphics().drawImage(sourceImage, 0, 0, null);
// create a sprite, add it the cache then return it
Sprite sprite = (Sprite) new AwtSprite(image, ref);
return sprite;
}
示例14: getCompatibleImage
import java.awt.GraphicsConfiguration; //導入方法依賴的package包/類
private static BufferedImage getCompatibleImage(GraphicsConfiguration gc,
int size) {
BufferedImage image = gc.createCompatibleImage(size, size);
Graphics2D g2d = image.createGraphics();
g2d.setColor(Color.GREEN);
g2d.fillRect(0, 0, size, size);
g2d.dispose();
return image;
}
示例15: getSourceGold
import java.awt.GraphicsConfiguration; //導入方法依賴的package包/類
private static BufferedImage getSourceGold(GraphicsConfiguration gc,
int size) {
final BufferedImage bi = gc.createCompatibleImage(size, size);
Graphics2D g2d = bi.createGraphics();
g2d.setColor(Color.RED);
g2d.fillRect(0, 0, size, size);
g2d.dispose();
return bi;
}