ios saving screenshots

This commit is contained in:
Bryce Covert
2017-02-25 09:27:34 -08:00
parent b378376dbc
commit 5f92863a5e

View File

@@ -0,0 +1,38 @@
package advent.core;
import org.robovm.apple.uikit.*;
import org.robovm.apple.coregraphics.*;
import org.robovm.apple.foundation.*;
import com.badlogic.gdx.*;
import com.badlogic.gdx.graphics.*;
import com.badlogic.gdx.backends.iosrobovm.*;
public class Saver {
public static Pixmap takeScreenshot(){
UIImage newImage;
UIGraphics.beginImageContext(new CGSize(1280, 960));
((IOSApplication) Gdx.app).getUIViewController().getView().drawViewHierarchy(
new CGRect(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()) , true);
newImage = UIGraphics.getImageFromCurrentImageContext();
UIGraphics.endImageContext();
NSData data = newImage.toPNGData();
newImage.dispose();
PixmapIO.PNG p = new PixmapIO.PNG();
Pixmap stepResult = new Pixmap(data.getBytes(), 0, data.getBytes().length);
p.setFlipY(true);
try {
p.write(Gdx.files.local("screenshot.png"), stepResult);
stepResult.dispose();
p.dispose();
return new Pixmap(Gdx.files.local("screenshot.png"));
} catch (Exception e) {
return new Pixmap(160, 120, Pixmap.Format.RGBA8888);
}
}
}