本文整理汇总了Java中com.badlogic.gdx.graphics.PixmapIO.writePNG方法的典型用法代码示例。如果您正苦于以下问题:Java PixmapIO.writePNG方法的具体用法?Java PixmapIO.writePNG怎么用?Java PixmapIO.writePNG使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.badlogic.gdx.graphics.PixmapIO
的用法示例。
在下文中一共展示了PixmapIO.writePNG方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: takeScreenshot
import com.badlogic.gdx.graphics.PixmapIO; //导入方法依赖的package包/类
public static void takeScreenshot() {
byte[] pixels = ScreenUtils.getFrameBufferPixels(0, 0,
Gdx.graphics.getBackBufferWidth(),
Gdx.graphics.getBackBufferHeight(), true);
Pixmap pixmap = new Pixmap(Gdx.graphics.getBackBufferWidth(),
Gdx.graphics.getBackBufferHeight(), Pixmap.Format.RGBA8888);
BufferUtils.copy(pixels, 0, pixmap.getPixels(), pixels.length);
SimpleDateFormat dateFormat = new SimpleDateFormat(
"yyyy-MM-dd HH-mm-ss");
PixmapIO.writePNG(
Gdx.files.external(dateFormat.format(new Date()) + ".png"),
pixmap);
pixmap.dispose();
}
示例2: writePixmaps
import com.badlogic.gdx.graphics.PixmapIO; //导入方法依赖的package包/类
/** A utility method to write the given array of pixmaps to the given output directory, with the specified file name. If the
* pages array is of length 1, then the resulting file ref will look like: "fileName.png".
*
* If the pages array is greater than length 1, the resulting file refs will be appended with "_N", such as "fileName_0.png",
* "fileName_1.png", "fileName_2.png" etc.
*
* The returned string array can then be passed to the <tt>writeFont</tt> method.
*
* Note: None of the pixmaps will be disposed.
*
* @param pages the pages of pixmap data to write
* @param outputDir the output directory
* @param fileName the file names for the output images
* @return the array of string references to be used with <tt>writeFont</tt> */
public static String[] writePixmaps (Pixmap[] pages, FileHandle outputDir, String fileName) {
if (pages == null || pages.length == 0) throw new IllegalArgumentException("no pixmaps supplied to BitmapFontWriter.write");
String[] pageRefs = new String[pages.length];
for (int i = 0; i < pages.length; i++) {
String ref = pages.length == 1 ? (fileName + ".png") : (fileName + "_" + i + ".png");
// the ref for this image
pageRefs[i] = ref;
// write the PNG in that directory
PixmapIO.writePNG(outputDir.child(ref), pages[i]);
}
return pageRefs;
}
示例3: writePixmaps
import com.badlogic.gdx.graphics.PixmapIO; //导入方法依赖的package包/类
/** A utility method to write the given array of pixmaps to the given output directory, with the specified file name. If the
* pages array is of length 1, then the resulting file ref will look like: "fileName.png".
*
* If the pages array is greater than length 1, the resulting file refs will be appended with "_N", such as "fileName_0.png",
* "fileName_1.png", "fileName_2.png" etc.
*
* The returned string array can then be passed to the <tt>writeFont</tt> method.
*
* Note: None of the pixmaps will be disposed.
*
* @param pages the pages of pixmap data to write
* @param outputDir the output directory
* @param fileName the file names for the output images
* @return the array of string references to be used with <tt>writeFont</tt> */
public static String[] writePixmaps (Pixmap[] pages, FileHandle outputDir, String fileName) {
if (pages==null || pages.length==0)
throw new IllegalArgumentException("no pixmaps supplied to BitmapFontWriter.write");
String[] pageRefs = new String[pages.length];
for (int i=0; i<pages.length; i++) {
String ref = pages.length==1 ? (fileName+".png") : (fileName+"_"+i+".png");
//the ref for this image
pageRefs[i] = ref;
//write the PNG in that directory
PixmapIO.writePNG(outputDir.child(ref), pages[i]);
}
return pageRefs;
}
示例4: writePixmaps
import com.badlogic.gdx.graphics.PixmapIO; //导入方法依赖的package包/类
/** A utility method to write the given array of pixmaps to the given output directory, with the specified file name. If the
* pages array is of length 1, then the resulting file ref will look like: "fileName.png".
*
* If the pages array is greater than length 1, the resulting file refs will be appended with "_N", such as "fileName_0.png",
* "fileName_1.png", "fileName_2.png" etc.
*
* The returned string array can then be passed to the <tt>writeFont</tt> method.
*
* Note: None of the pixmaps will be disposed.
*
* @param pages the pages of pixmap data to write
* @param outputDir the output directory
* @param fileName the file names for the output images
* @return the array of string references to be used with <tt>writeFont</tt> */
public static String[] writePixmaps (Pixmap[] pages, FileHandle outputDir, String fileName) {
if (pages==null || pages.length==0)
throw new IllegalArgumentException("no pixmaps supplied to BitmapFontWriter.write");
String[] pageRefs = new String[pages.length];
for (int i=0; i<pages.length; i++) {
String ref = pages.length==1 ? (fileName+".png") : (fileName+"_"+i+".png");
//the ref for this image
pageRefs[i] = ref;
//write the PNG in that directory
PixmapIO.writePNG(outputDir.child(ref), pages[i]);
}
return pageRefs;
}
示例5: saveScreenshot
import com.badlogic.gdx.graphics.PixmapIO; //导入方法依赖的package包/类
public static void saveScreenshot(final int w, final int h, final String prefix)
{
try
{
FileHandle fh;
do
{
if (Gdx.app.getType() == ApplicationType.Desktop)
{
fh = Gdx.files.local("bin/screenshot_" + prefix + "_" + counter++ + ".png");
}
else
{
fh = Gdx.files.local("screenshot_" + prefix + "_" + counter++ + ".png");
}
}
while (fh.exists());
final Pixmap pixmap = getScreenshot(0, 0, w, h, true);
PixmapIO.writePNG(fh, pixmap);
pixmap.dispose();
Gdx.app.log("screenshot", "Screenshot saved to " + fh);
}
catch (final Exception e)
{
}
}
示例6: screenshot
import com.badlogic.gdx.graphics.PixmapIO; //导入方法依赖的package包/类
public void screenshot(String filename) {
if (fbo != null) {
FileHandle local = Gdx.files.local(filename);
try {
FileHandle fh;
do {
fh = local;
} while (fh.exists());
byte[] frameBufferPixels = ScreenUtils.getFrameBufferPixels(0, 0, G.CANVAS_WIDTH, G.CANVAS_HEIGHT, true);
Pixmap pixmap = new Pixmap(G.CANVAS_WIDTH, G.CANVAS_HEIGHT, Pixmap.Format.RGBA8888);
pixmap.getPixels().put(frameBufferPixels);
PixmapIO.writePNG(fh, pixmap);
pixmap.dispose();
fbo.end();
fbo.dispose();
} catch (Exception e) {
}
}
}
示例7: writePixmaps
import com.badlogic.gdx.graphics.PixmapIO; //导入方法依赖的package包/类
/** A utility method to write the given array of pixmaps to the given output directory, with the specified file name. If the
* pages array is of length 1, then the resulting file ref will look like: "fileName.png".
*
* If the pages array is greater than length 1, the resulting file refs will be appended with "_N", such as "fileName_0.png",
* "fileName_1.png", "fileName_2.png" etc.
*
* The returned string array can then be passed to the <tt>writeFont</tt> method.
*
* Note: None of the pixmaps will be disposed.
*
* @param pages the pages of pixmap data to write
* @param outputDir the output directory
* @param fileName the file names for the output images
* @return the array of string references to be used with <tt>writeFont</tt> */
public static String[] writePixmaps (Pixmap[] pages, FileHandle outputDir, String fileName) {
if (pages == null || pages.length == 0)
throw new IllegalArgumentException("no pixmaps supplied to BitmapFontWriter.write");
String[] pageRefs = new String[pages.length];
for (int i = 0; i < pages.length; i++) {
String ref = pages.length == 1 ? (fileName + ".png") : (fileName + "_" + i + ".png");
// the ref for this image
pageRefs[i] = ref;
// write the PNG in that directory
PixmapIO.writePNG(outputDir.child(ref), pages[i]);
}
return pageRefs;
}
示例8: saveScreenshot
import com.badlogic.gdx.graphics.PixmapIO; //导入方法依赖的package包/类
private static void saveScreenshot() throws IOException {
int w = Gdx.graphics.getWidth();
int h = Gdx.graphics.getHeight();
final Pixmap pixmap = new Pixmap(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), Format.RGBA8888);
ByteBuffer pixels = pixmap.getPixels();
Gdx.gl.glReadPixels(0, 0, w, h, GL20.GL_RGBA, GL20.GL_UNSIGNED_BYTE, pixels);
final int numBytes = w * h * 4;
byte[] lines = new byte[numBytes];
final int numBytesPerLine = w * 4;
for (int i = 0; i < h; i++) {
pixels.position((h - i - 1) * numBytesPerLine);
pixels.get(lines, i * numBytesPerLine, numBytesPerLine);
}
pixels.clear();
pixels.put(lines);
System.out.println("Captured.");
PixmapIO.writePNG(new FileHandle(androidDir+(++photoNumber)+".png"), pixmap);
}
示例9: writePixmapToImage
import com.badlogic.gdx.graphics.PixmapIO; //导入方法依赖的package包/类
public static String writePixmapToImage(String absoluteLocation, String baseFileName, Pixmap pixmap, ImageType type) {
/** Make sure the directory exists **/
FileHandle dir = Gdx.files.absolute(absoluteLocation);
dir.mkdirs();
/** Save to file **/
FileHandle fh = getTarget(absoluteLocation, baseFileName, type);
switch (type) {
case PNG:
PixmapIO.writePNG(fh, pixmap);
break;
case JPG:
JPGWriter.write(fh, pixmap);
break;
}
return fh.path();
}
示例10: saveScreenshot
import com.badlogic.gdx.graphics.PixmapIO; //导入方法依赖的package包/类
public static String saveScreenshot(String destinationFolder, boolean yDown){
FileHandle fh;
try{
do{
fh = new FileHandle(destinationFolder + "snappyfrog-" + counter++ + ".png");
}while (fh.exists());
Pixmap pixmap = getScreenshot(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), yDown);
PixmapIO.writePNG(fh, pixmap);
pixmap.dispose();
}catch (Exception e){
System.out.println("Error happened while saving screenshot: " + e.getMessage());
return "";
}
return fh.path();
}
示例11: saveScreen
import com.badlogic.gdx.graphics.PixmapIO; //导入方法依赖的package包/类
public static void saveScreen() {
int count = 0;
try {
FileHandle f;
do {
f = new FileHandle("screenshoot"+ count++ +".png");
}while(f.exists());
Pixmap px = takeScreenShoot();
PixmapIO.writePNG(f, px);
px.dispose();
}catch(Exception e) {
e.printStackTrace();
}
}
示例12: makeScreenshot
import com.badlogic.gdx.graphics.PixmapIO; //导入方法依赖的package包/类
private void makeScreenshot(){
int w = Gdx.graphics.getWidth();
int h = Gdx.graphics.getHeight();
Gdx.gl.glPixelStorei(GL10.GL_PACK_ALIGNMENT, 1);
final Pixmap pixmap = new Pixmap(w, h, Format.RGBA8888);
ByteBuffer pixels = pixmap.getPixels();
Gdx.gl.glReadPixels(0, 0, w, h, GL10.GL_RGBA, GL10.GL_UNSIGNED_BYTE, pixels);
final int numBytes = w * h * 4;
byte[] lines = new byte[numBytes];
pixels.clear();
pixels.get(lines);
String stamp = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss").format(Calendar.getInstance().getTime());
PixmapIO.writePNG(Gdx.files.local("Screenshot-" + stamp + ".png"), pixmap);
pixmap.dispose();
}
示例13: createImage
import com.badlogic.gdx.graphics.PixmapIO; //导入方法依赖的package包/类
private void createImage() {
Pixmap pixmap = new Pixmap(200, 200, Format.RGBA8888);
pixmap.setColor((float) Math.random(), (float) Math.random(),
(float) Math.random(), 1.0f);
pixmap.fill();
PixmapIO.writePNG(
controller.getApplicationAssets().absolute(
file.getAbsolutePath()), pixmap);
Gdx.app.postRunnable(new Runnable() {
@Override
public void run() {
controller.getEditorGameAssets().unload(file.toString());
controller.getEditorGameAssets().load(file.toString(),
Texture.class);
}
});
}
示例14: frameSave
import com.badlogic.gdx.graphics.PixmapIO; //导入方法依赖的package包/类
public static void frameSave(final FileHandle fh) {
final int w = (int) Shadow.dispw;
final int h = (int) Shadow.disph;
final byte[] data = getScreenData(0, 0, w, h);
Thread thread = new Thread("Screenshot_"+Shadow.rand.nextInt(1024)) {
@Override
public void run() {
Pixmap pixmap = getPixmap(w, h);
fillPixmap(pixmap, data);
fh.parent().mkdirs();
PixmapIO.writePNG(fh, pixmap);
}
};
thread.start();
}
示例15: take
import com.badlogic.gdx.graphics.PixmapIO; //导入方法依赖的package包/类
public static void take(String createInPath) {
String prefix;
if (Strings.isNullOrEmpty(createInPath))
prefix = "screenshot";
else if (createInPath.endsWith("/"))
prefix = createInPath + "screenshot";
else
prefix = createInPath + "/screenshot";
try {
FileHandle file;
do {
file = new FileHandle(prefix + counter + ".png");
counter++;
} while (file.exists());
Pixmap pixmap = getFrameBufferPixmap(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), true);
PixmapIO.writePNG(file, pixmap);
pixmap.dispose();
Gdx.app.log("Screenshot", String.format("Saved screenshot to %s", file.file().getAbsolutePath()));
} catch (Exception e) {
}
}