當前位置: 首頁>>代碼示例>>Java>>正文


Java PixmapIO類代碼示例

本文整理匯總了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();
}
 
開發者ID:eskalon,項目名稱:ProjektGG,代碼行數:18,代碼來源:ScreenshotUtils.java

示例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;
}
 
開發者ID:RedTroop,項目名稱:Cubes_2,代碼行數:31,代碼來源:BitmapFontWriter.java

示例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;
}
 
開發者ID:TudorRosca,項目名稱:enklave,代碼行數:32,代碼來源:BitmapFontWriter.java

示例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;
}
 
開發者ID:Radomiej,項目名稱:JavityEngine,代碼行數:32,代碼來源:BitmapFontWriter.java

示例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)
    {
    }
}
 
開發者ID:ncguy2,項目名稱:Argent,代碼行數:27,代碼來源:ScreenshotFactory.java

示例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;
}
 
開發者ID:Inari-Soft,項目名稱:inari-firefly-libGDX,代碼行數:18,代碼來源:FilteredTextureData.java

示例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) {
		}
	}
}
 
開發者ID:DaanVanYperen,項目名稱:ns2-scc-profiler,代碼行數:22,代碼來源:ScreenshotHelper.java

示例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.");
	}
}
 
開發者ID:DaanVanYperen,項目名稱:ns2-scc-profiler,代碼行數:17,代碼來源:ScreenshotHelper.java

示例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;
}
 
開發者ID:basherone,項目名稱:libgdxcn,代碼行數:32,代碼來源:BitmapFontWriter.java

示例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);
}
 
開發者ID:randombot,項目名稱:gametemplate,代碼行數:19,代碼來源:MarketUtils.java

示例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();
}
 
開發者ID:langurmonkey,項目名稱:gaiasky,代碼行數:18,代碼來源:ImageRenderer.java

示例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();
}
 
開發者ID:pierotofy,項目名稱:snappyfrog,代碼行數:17,代碼來源:ScreenshotFactory.java

示例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();
	}
}
 
開發者ID:costular,項目名稱:crabox,代碼行數:17,代碼來源:Utils.java

示例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();
}
 
開發者ID:madpew,項目名稱:libgdx-lwp-template,代碼行數:19,代碼來源:TemplateMain.java

示例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);
		}
	});
}
 
開發者ID:e-ucm,項目名稱:ead,代碼行數:19,代碼來源:AsyncImageTest.java


注:本文中的com.badlogic.gdx.graphics.PixmapIO類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。