Capture Screen in libGdx -


i want capture screen in libgdx . use code problem. on desktop work . when run on android , can't find image capture screen. how can fix it? reading question.

public class screenshotfactory {  private static int counter = 1;  public static void savescreenshot() {     try {         filehandle fh;         {              if (gdx.app.gettype() == applicationtype.desktop)                 infor.linkscreenshot = "d://chupngoc" + counter + ".png";             else                 infor.linkscreenshot = gdx.files.getexternalstoragepath()                         + counter + ".png";             infor.nameimage = counter + ".png";             fh = new filehandle(infor.linkscreenshot);             counter++;         } while (fh.exists());          pixmap pixmap = getscreenshot(0, 0, gdx.graphics.getwidth(),                 gdx.graphics.getheight(), true);         pixmapio.writepng(fh, pixmap);         pixmap.dispose();     } catch (exception e) {     } }  private static pixmap getscreenshot(int x, int y, int w, int h,         boolean ydown) {      gdx.gl.glpixelstorei(gl20.gl_pack_alignment, 1);      final pixmap pixmap1 = new pixmap(w, h, format.rgba8888);     bytebuffer pixels1 = pixmap1.getpixels();     gdx.gl.glreadpixels(x, y, w, h, gl20.gl_rgba, gl20.gl_unsigned_byte,             pixels1);      pixmap pixmap = pixmap1;      if (ydown) {         // flip pixmap upside down         bytebuffer pixels = pixmap.getpixels();         int numbytes = w * h * 4;         byte[] lines = new byte[numbytes];         int numbytesperline = w * 4;         (int = 0; < h; i++) {             pixels.position((h - - 1) * numbytesperline);             pixels.get(lines, * numbytesperline, numbytesperline);         }         pixels.clear();         pixels.put(lines);     }      return pixmap; } 

}

your problem lies here...

fh = new filehandle(infor.linkscreenshot); 

this way of creating filehandle desktop , not work on android.

you should create file using gdx.files.external instead...

fh = gdx.files.external(infor.linkscreenshot); 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -