本文整理匯總了Java中com.badlogic.gdx.graphics.PixmapIO類的典型用法代碼示例。如果您正苦於以下問題:Java PixmapIO類的具體用法?Java PixmapIO怎麽用?Java PixmapIO使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
PixmapIO類屬於com.badlogic.gdx.graphics包,在下文中一共展示了PixmapIO類的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: prepare
import com.badlogic.gdx.graphics.PixmapIO; //導入依賴的package包/類
@Override
public void prepare () {
if (isPrepared) throw new GdxRuntimeException("Already prepared");
if (pixmap == null) {
if (file.extension().equals("cim"))
pixmap = PixmapIO.readCIM(file);
else
pixmap = ensurePot(new Pixmap(file));
width = pixmap.getWidth();
height = pixmap.getHeight();
if (format == null) format = pixmap.getFormat();
}
applyFilter( pixmap );
isPrepared = true;
}
示例7: 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) {
}
}
}
示例8: saveMapTexture
import com.badlogic.gdx.graphics.PixmapIO; //導入依賴的package包/類
public void saveMapTexture(GameState state, Layer layer) {
Pixmap pixmap = layer.pixmap;
try {
PixmapIO.PNG writer = new PixmapIO.PNG((int) (pixmap.getWidth() * pixmap.getHeight() * 1.5f)); // Guess at deflated size.
try {
writer.setFlipY(false);
ByteArrayOutputStream pngStream = new ByteArrayOutputStream();
writer.write(pngStream, pixmap);
state.layer = pngStream.toByteArray();
} finally {
writer.dispose();
}
} catch (IOException ex) {
throw new RuntimeException("Could not save map as texture.");
}
}
示例9: 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;
}
示例10: 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);
}
示例11: 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();
}
示例12: 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();
}
示例13: 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();
}
}
示例14: 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();
}
示例15: 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);
}
});
}