I need to write an image from the IOS gallery to a file to be used in my app. I dont speak Obj-C, neither can I translate Obj-C to RoboVM´s Java library. What I think would be the easiest for me to understand is to use InputStream to write the image to a file. So this is what I got going so far:
@Override
public void iosPickImage(final InputStream stream) {
// Gallery
MyDelegatePicker delegate = new MyDelegatePicker() {
@Override
public void didFinishPickingMedia(UIImagePickerController picker, UIImagePickerControllerEditingInfo info) {
UIImage selectedImage = info.getOriginalImage();
File file = new File(Gdx.files.getExternalStoragePath() + "selectedPhoto1.bin");
try {
file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
try {
FileInputStream fileStream = new FileInputStream(file);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
try {
stream.read(selectedImage.toPNGData().getBytes());
} catch (IOException e) {
e.printStackTrace();
}
picker.dismissViewController(true, null);
}
@Override
public void didCancel(UIImagePickerController picker) {
}
};
UIViewController controller = ((IOSApplication) Gdx.app).getUIViewController();
MyImagePickerController imagePicker = new MyImagePickerController();
controller.addChildViewController(imagePicker);
controller.getView().addSubview(imagePicker.getView());
imagePicker.getView().setBounds(controller.getView().getBounds());
imagePicker.setSourceType(UIImagePickerControllerSourceType.PhotoLibrary);
imagePicker.setDelegate(delegate);
imagePicker.addStrongRef((ObjCObject) delegate);
//Gdx.app.exit();
}
And then by passing that method through my interface :
public void iosGallery(final InputStream stream) {
gallery.iosPickImage(stream);
}
This as you can see is far from finished. I would like to use Callback and AsyncExecutor to finish this off, but the RoboVM library dont support those classes. So anyone got an idea on how to finish this method or rewrite it to work?
Aucun commentaire:
Enregistrer un commentaire