本文整理了Java中playn.core.Graphics.createImage()
方法的一些代码示例,展示了Graphics.createImage()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Graphics.createImage()
方法的具体详情如下:
包路径:playn.core.Graphics
类名称:Graphics
方法名:createImage
[英]Creates an image that can be painted using the Canvas interface.
[中]创建可以使用画布界面绘制的图像。
代码示例来源:origin: threerings/playn
public Label(float wid, float hei, TextFormat format) {
image = graphics().createImage(wid, hei);
layer = graphics().createImageLayer(image);
this.format = format;
}
代码示例来源:origin: threerings/playn
private CanvasImage createCanvasImage(int width, int height, final Drawer drawer) {
final CanvasImage image = graphics().createImage(width, height);
drawer.draw(image.canvas());
return image;
}
代码示例来源:origin: threerings/playn
private void addTestCanvas(String descrip, int width, int height, String imagePath,
final ImageDrawer drawer) {
final CanvasImage target = graphics().createImage(width, height);
assets().getImage(imagePath).addCallback(new Callback<Image>() {
public void onSuccess(Image image) {
drawer.draw(target.canvas(), image);
}
public void onFailure(Throwable err) {
System.err.println("Oops! " + err);
}
});
addTestLayer(descrip, width, height, graphics().createImageLayer(target));
}
代码示例来源:origin: com.googlecode.playn/playn-tests-core
private CanvasImage createCanvasImage(int width, int height, final Drawer drawer) {
final CanvasImage image = graphics().createImage(width, height);
drawer.draw(image.canvas());
return image;
}
代码示例来源:origin: com.googlecode.playn/playn-tests-core
private void addTestCanvas(int width, int height, String imagePath, final ImageDrawer drawer) {
final CanvasImage target = graphics().createImage(width, height);
assets().getImage(imagePath).addCallback(new ResourceCallback<Image>() {
public void done(Image image) {
drawer.draw(target.canvas(), image);
}
public void error(Throwable err) {
System.err.println("Oops! " + err);
}
});
addTestLayer(width, height, graphics().createImageLayer(target));
}
}
代码示例来源:origin: threerings/playn
protected void updateDisplay() {
StringBuffer buf = new StringBuffer();
if (notifications.isEmpty()) {
buf.append("No notifications. Pause and resume the game to generate some.");
} else {
buf.append("Notifications:\n");
for (String note : notifications)
buf.append(note).append("\n");
}
TextLayout layout = graphics().layoutText(buf.toString(), new TextFormat());
CanvasImage image = graphics().createImage(layout.width(), layout.height());
image.canvas().setFillColor(0xFF000000);
image.canvas().fillText(layout, 0, 0);
layer.setImage(image);
}
}
代码示例来源:origin: threerings/playn
@Override
public void init() {
CanvasImage canvasImage = graphics().createImage(graphics().width(), graphics().height());
canvas = canvasImage.canvas();
graphics().rootLayer().add(graphics().createImageLayer(canvasImage));
}
代码示例来源:origin: threerings/playn
/**
* Returns a (created on demand, then cached) image used when filling solid color quads or
* triangles.
*/
Image fillImage() {
if (fillImage == null) {
CanvasImage image = platform.graphics().createImage(1, 1);
image.canvas().setFillColor(0xFFFFFFFF).fillRect(0, 0, image.width(), image.height());
fillImage = image;
}
return fillImage;
}
代码示例来源:origin: threerings/playn
@Override
public void onSuccess(Image image) {
// once the image loads, create our layers
imageLayer1 = graphics().createImageLayer(image);
SurfaceImage surface1 = graphics().createSurface(image.width(), image.height());
surface1.surface().drawImage(image, 0, 0);
surfaceLayer1 = graphics().createImageLayer(surface1);
CanvasImage canvas1 = graphics().createImage(image.width(), image.height());
canvas1.canvas().drawImage(image, 0, 0);
canvasLayer1 = graphics().createImageLayer(canvas1);
imageLayer2 = graphics().createImageLayer(image);
SurfaceImage surface2 = graphics().createSurface(image.width(), image.height());
surface2.surface().drawImage(image, 0, 0);
surfaceLayer2 = graphics().createImageLayer(surface2);
CanvasImage canvas2 = graphics().createImage(image.width(), image.height());
canvas2.canvas().drawImage(image, 0, 0);
canvasLayer2 = graphics().createImageLayer(canvas2);
// add layers to the rootLayer
rootLayer.addAt(imageLayer1, offset, offset);
rootLayer.addAt(surfaceLayer1, offset + width, offset);
rootLayer.addAt(canvasLayer1, offset + 2 * width, offset);
rootLayer.addAt(imageLayer2, offset, offset + 2 * height);
rootLayer.addAt(surfaceLayer2, offset + width, offset + 2 * height);
rootLayer.addAt(canvasLayer2, offset + 2 * width, offset + 2 * height);
}
代码示例来源:origin: threerings/playn
/**
* Creates a canvas image large enough to accommodate this text block and renders the lines into
* it. The image will include padding around the edge to ensure that antialiasing has a bit of
* extra space to do its work.
*/
public CanvasImage toImage(Align align, int fillColor) {
float pad = pad();
CanvasImage image = graphics().createImage(bounds.width()+2*pad, bounds.height()+2*pad);
image.canvas().setFillColor(fillColor);
fill(image.canvas(), align, pad, pad);
return image;
}
}
代码示例来源:origin: threerings/playn
@Override
public void init() {
GroupLayer rootLayer = graphics().rootLayer();
CanvasImage image = graphics().createImage(250, 25);
image.canvas().drawText(rootLayer.getClass().getName(), 0, 15);
ImageLayer info = graphics().createImageLayer(image);
info.setTranslation(5, 5);
rootLayer.add(info);
int[] depths = { 0, -1, 1, 3, 2, -4, -3, 4, -2 };
int[] fills = { 0xFF99CCFF, 0xFFFFFF33, 0xFF9933FF, 0xFF999999, 0xFFFF0033,
0xFF00CC00, 0xFFFF9900, 0xFF0066FF, 0x0FFCC6666 };
int width = 200, height = 200;
for (int ii = 0; ii < depths.length; ii++) {
int depth = depths[ii];
image = graphics().createImage(width, height);
image.canvas().setFillColor(fills[ii]);
image.canvas().fillRect(0, 0, width, height);
image.canvas().setFillColor(0xFF000000);
image.canvas().drawText(depth + "/" + ii, 5, 15);
ImageLayer layer = graphics().createImageLayer(image);
layer.setDepth(depth);
layer.setTranslation(225-50*depth, 125+25*depth);
rootLayer.add(layer);
}
}
}
代码示例来源:origin: threerings/playn
protected Image makeLabel(String label) {
TextLayout layout = graphics().layoutText(label, new TextFormat());
CanvasImage image = graphics().createImage(layout.width(), layout.height());
image.canvas().setFillColor(0xFF000000);
image.canvas().fillText(layout, 0, 0);
return image;
}
代码示例来源:origin: com.googlecode.playn/playn-tests-core
@Override
public void init() {
GroupLayer rootLayer = graphics().rootLayer();
CanvasImage image = graphics().createImage(250, 20);
image.canvas().drawText(rootLayer.getClass().getName(), 0, 15);
ImageLayer info = graphics().createImageLayer(image);
info.setTranslation(5, 5);
rootLayer.add(info);
int[] depths = { 0, -1, 1, 3, 2, -4, -3, 4, -2 };
int[] fills = { 0xFF99CCFF, 0xFFFFFF33, 0xFF9933FF, 0xFF999999, 0xFFFF0033,
0xFF00CC00, 0xFFFF9900, 0xFF0066FF, 0x0FFCC6666 };
int width = 200, height = 200;
for (int ii = 0; ii < depths.length; ii++) {
int depth = depths[ii];
image = graphics().createImage(width, height);
image.canvas().setFillColor(fills[ii]);
image.canvas().fillRect(0, 0, width, height);
image.canvas().setFillColor(0xFF000000);
image.canvas().drawText(depth + "/" + ii, 5, 15);
ImageLayer layer = graphics().createImageLayer(image);
layer.setDepth(depth);
layer.setTranslation(225-50*depth, 125+25*depth);
rootLayer.add(layer);
}
}
}
代码示例来源:origin: threerings/playn
protected static CanvasImage formatText (TextFormat format, String text, boolean border) {
TextLayout layout = graphics().layoutText(text, format);
float margin = border ? 10 : 0;
float width = layout.width()+2*margin, height = layout.height()+2*margin;
CanvasImage image = graphics().createImage(width, height);
image.canvas().setStrokeColor(0xFF000000);
image.canvas().setFillColor(0xFF000000);
image.canvas().fillText(layout, margin, margin);
if (border)
image.canvas().strokeRect(0, 0, width-1, height-1);
return image;
}
代码示例来源:origin: threerings/playn
protected void addInfo (CanvasImage image, float cx, float y) {
TextLayout ilayout = graphics().layoutText(image.width() + "x" + image.height(), infoFormat);
CanvasImage iimage = graphics().createImage(ilayout.width(), ilayout.height());
iimage.canvas().setFillColor(0xFF000000).fillText(ilayout, 0, 0);
graphics().rootLayer().addAt(graphics().createImageLayer(iimage), cx - iimage.width()/2, y);
}
代码示例来源:origin: threerings/playn
public static Image makeButtonImage(String label) {
TextLayout layout = graphics().layoutText(label, BUTTON_FMT);
CanvasImage image = graphics().createImage(layout.width()+10, layout.height()+10);
image.canvas().setFillColor(0xFFCCCCCC);
image.canvas().fillRect(0, 0, image.width(), image.height());
image.canvas().setFillColor(0xFF000000);
image.canvas().fillText(layout, 5, 5);
image.canvas().setStrokeColor(0xFF000000);
image.canvas().strokeRect(0, 0, image.width()-1, image.height()-1);
return image;
}
代码示例来源:origin: threerings/playn
protected ImageLayer createLabel(String text, GroupLayer parent,
int fg, int bg, float x, float y, float padding) {
TextLayout layout = graphics().layoutText(text, baseFormat);
float twidth = layout.width() + padding * 2;
float theight = layout.height() + padding * 2;
CanvasImage image = graphics().createImage(twidth, theight);
if (bg != 0) {
image.canvas().setFillColor(bg);
image.canvas().fillRect(0, 0, twidth, theight);
}
image.canvas().setFillColor(fg);
image.canvas().fillText(layout, padding, padding);
ImageLayer imageLayer = graphics().createImageLayer(image);
imageLayer.setTranslation(x, y);
parent.add(imageLayer);
return imageLayer;
}
代码示例来源:origin: threerings/playn
protected Image makeTextImage() {
TextFormat format = new TextFormat(graphics().createFont(font.value(), style.value(), 24), true);
float wrapWidth = wrap.value() == 0 ? Float.MAX_VALUE : graphics().width()*wrap.value()/100;
TextBlock block = new TextBlock(graphics().layoutText(sample, format, new TextWrap(wrapWidth)));
float awidth = adjustWidth(block.bounds.width()), aheight = adjustHeight(block.bounds.height());
float pad = TextBlock.pad();
CanvasImage image = graphics().createImage(awidth+2*pad, aheight+2*pad);
image.canvas().translate(pad, pad);
image.canvas().setStrokeColor(0xFFFFCCCC).strokeRect(0, 0, awidth, aheight);
render(image.canvas(), block, align.value(), lineBounds.value());
return image;
}
代码示例来源:origin: threerings/playn
@Override public void init () {
GroupLayer slider = graphics().createGroupLayer();
CanvasImage image = graphics().createImage(WIDTH + 10, HEIGHT);
image.canvas().setFillColor(0xff808080);
image.canvas().fillRect(0, 0, WIDTH + 10, HEIGHT);
ImageLayer bg = graphics().createImageLayer(image);
slider.add(bg);
image = graphics().createImage(WIDTH, HWIDTH);
image.canvas().setFillColor(0xffffffff);
image.canvas().fillRect(0, 0, WIDTH, HWIDTH);
image.canvas().setStrokeColor(0xff000000);
image.canvas().drawLine(0, HWIDTH / 2, WIDTH, HWIDTH / 2);
image.canvas().setStrokeColor(0xffff0000);
image.canvas().strokeRect(0, 0, WIDTH - 1, HWIDTH - 1);
slider.add(il = graphics().createImageLayer(image));
il.setOrigin(0, HWIDTH / 2);
il.setTranslation(0, HEIGHT / 2);
il.setDepth(1);
graphics().rootLayer().add(slider);
slider.setTranslation(25, 25);
bg.addListener(new Mouse.LayerAdapter() {
@Override public void onMouseWheelScroll (WheelEvent event) {
float y = il.ty() + event.velocity();
y = Math.max(0, Math.min(y, HEIGHT));
il.setTranslation(0, y);
}
});
}
代码示例来源:origin: threerings/playn
@Override
public void init() {
String text = "The quick brown fox jumped over the lazy dog.";
TextFormat format = new TextFormat().
withFont(graphics().createFont("Helvetica", Font.Style.PLAIN, 18));
TextBlock block = new TextBlock(graphics().layoutText(text, format, new TextWrap(100)));
float x = 5;
for (float scale : new float[] { 1f, 2f, 3f }) {
float swidth = block.bounds.width() * scale, sheight = block.bounds.height() * scale;
CanvasImage image = graphics().createImage(swidth, sheight);
image.canvas().setStrokeColor(0xFFFFCCCC).strokeRect(0, 0, swidth-0.5f, sheight-0.5f);
image.canvas().scale(scale, scale);
image.canvas().setFillColor(0xFF000000);
block.fill(image.canvas(), TextBlock.Align.RIGHT, 0, 0);
graphics().rootLayer().addAt(graphics().createImageLayer(image), x, 5);
addInfo(image, x + swidth/2, sheight + 10);
x += swidth + 5;
}
}
内容来源于网络,如有侵权,请联系作者删除!