Skip to content

Instantly share code, notes, and snippets.

@jsfan3
Last active May 7, 2020 09:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jsfan3/7fc101523955e8179fadd2c713a09e05 to your computer and use it in GitHub Desktop.
Save jsfan3/7fc101523955e8179fadd2c713a09e05 to your computer and use it in GitHub Desktop.
Codename One Image.exifRotation usage example
Form hi = new Form("Hi World", BoxLayout.y());
Button cameraBtn = new Button("Open Camera");
Button galleryBtn = new Button("Open Gallery");
Label imageLbl = new Label();
hi.addAll(cameraBtn, galleryBtn, FlowLayout.encloseCenter(imageLbl));
hi.show();
SuccessCallback<String> callback = (String capturedPhoto) -> {
String rotatedPhoto = FileSystemStorage.getInstance().getAppHomePath() + "rotatedPhoto.jpg";
if (capturedPhoto != null) {
try {
// note: we set a maxSize to perform a faster rotation
int maxSize = CN.convertToPixels(50);
Image img = Image.exifRotation(capturedPhoto, rotatedPhoto, maxSize);
imageLbl.setIcon(img);
hi.revalidate();
} catch (IOException ex) {
Log.e(ex);
}
};
};
cameraBtn.addActionListener(a -> Capture.capturePhoto(l -> {
if (l != null && l.getSource() != null) {
callback.onSucess((String) l.getSource());
}
}));
galleryBtn.addActionListener(a -> CN.openGallery(l -> {
if (l != null && l.getSource() != null) {
callback.onSucess((String) l.getSource());
}
}, CN.GALLERY_IMAGE));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment