(官网:www.libgdx.cn

接下来的示例说明怎样进行截屏并且保存为PNG格式。

public class ScreenshotFactory {
private static int counter = 1;
public static void saveScreenshot(){
try{
FileHandle fh;
do{
fh = new FileHandle("screenshot" + counter++ + ".png");
}while (fh.exists());
Pixmap pixmap = getScreenshot(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), false);
PixmapIO.writePNG(fh, pixmap);
pixmap.dispose();
}catch (Exception e){
}
} private static Pixmap getScreenshot(int x, int y, int w, int h, boolean yDown){
final Pixmap pixmap = ScreenUtils.getFrameBufferPixmap(x, y, w, h);
if (yDown) {
ByteBuffer pixels = pixmap.getPixels();
int numBytes = w * h * 4;
byte[] lines = new byte[numBytes];
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);
} return pixmap;
}
}

www.libgdx.cn版权所有,如需转载,注明出处)

最新文章

  1. SpringMVC 数据校验
  2. VS 2010一步步开发windows服务(windows service)
  3. c++ chap1 to chap 3
  4. clustershell
  5. Java开发中经典的小实例-(100能被3整除的数打印出来)
  6. Excel VBA自动添加证书(二)
  7. python 代码片段14
  8. Could not resolve archetype org.apache.maven.archetypes:maven-archetype-webapp:RELEASE from any of the configured repositories.
  9. K Best(最大化平均数)_二分搜索
  10. 打开自定义链接新窗口(safari JS prompt的坑!)2016.03.08
  11. Codeforces554D:Kyoya and Permutation
  12. Metrics监控应用
  13. Angular JS中的路由
  14. 理解Java类加载机制(译文)
  15. VBC#代码互转工具
  16. 1DAY centos 7.4 u盘安装、网络安装
  17. @synchronized深入理解
  18. 【JVM.12】线程安全与锁优化
  19. spring.schemas和spring.handlers对xmlns配置文件作用
  20. rabbitmq 部署(二进制和rpm)与常用命令

热门文章

  1. 混合式应用开发之Cordova+vue(1)
  2. 深入理解null的原理
  3. java里String类为何被设计为final
  4. ctf writeup之程序员密码
  5. env-cmd 从文件读取配置变量
  6. MPAndroidChart图形联动
  7. Android Multimedia框架总结(二十二)MediaCodec中C++中创建到start过程及状态变换
  8. 《Shazam It! Music Recognition Algorithms, Fingerprinting, and Processing》译文
  9. FORM内置系统变量
  10. Android Multimedia框架总结(九)Stagefright框架之数据处理及到OMXCodec过程