ios saving screenshots
This commit is contained in:
38
ios/src/java/advent/core/Saver.java
Normal file
38
ios/src/java/advent/core/Saver.java
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user