12.3、Libgdx的图像之截屏
2024-09-25 07:46:16
(官网: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版权所有,如需转载,注明出处)
最新文章
- SpringMVC 数据校验
- VS 2010一步步开发windows服务(windows service)
- c++ chap1 to chap 3
- clustershell
- Java开发中经典的小实例-(100能被3整除的数打印出来)
- Excel VBA自动添加证书(二)
- python 代码片段14
- Could not resolve archetype org.apache.maven.archetypes:maven-archetype-webapp:RELEASE from any of the configured repositories.
- K Best(最大化平均数)_二分搜索
- 打开自定义链接新窗口(safari JS prompt的坑!)2016.03.08
- Codeforces554D:Kyoya and Permutation
- Metrics监控应用
- Angular JS中的路由
- 理解Java类加载机制(译文)
- VBC#代码互转工具
- 1DAY centos 7.4 u盘安装、网络安装
- @synchronized深入理解
- 【JVM.12】线程安全与锁优化
- spring.schemas和spring.handlers对xmlns配置文件作用
- rabbitmq 部署(二进制和rpm)与常用命令
热门文章
- 混合式应用开发之Cordova+vue(1)
- 深入理解null的原理
- java里String类为何被设计为final
- ctf writeup之程序员密码
- env-cmd 从文件读取配置变量
- MPAndroidChart图形联动
- Android Multimedia框架总结(二十二)MediaCodec中C++中创建到start过程及状态变换
- 《Shazam It! Music Recognition Algorithms, Fingerprinting, and Processing》译文
- FORM内置系统变量
- Android Multimedia框架总结(九)Stagefright框架之数据处理及到OMXCodec过程