Last active
May 7, 2020 09:48
-
-
Save jsfan3/7fc101523955e8179fadd2c713a09e05 to your computer and use it in GitHub Desktop.
Codename One Image.exifRotation usage example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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