Created
February 28, 2016 12:23
-
-
Save codenameone/b18c37dfcc7de752e0e6 to your computer and use it in GitHub Desktop.
Example for using the Image masking and camera capture API's in Codename One
This file contains hidden or 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
Toolbar.setGlobalToolbar(true); | |
Form hi = new Form("Rounder", new BorderLayout()); | |
Label picture = new Label("", "Container"); | |
hi.add(BorderLayout.CENTER, picture); | |
hi.getUnselectedStyle().setBgColor(0xff0000); | |
hi.getUnselectedStyle().setBgTransparency(255); | |
Style s = UIManager.getInstance().getComponentStyle("TitleCommand"); | |
Image camera = FontImage.createMaterial(FontImage.MATERIAL_CAMERA, s); | |
hi.getToolbar().addCommandToRightBar("", camera, (ev) -> { | |
try { | |
int width = Display.getInstance().getDisplayWidth(); | |
Image capturedImage = Image.createImage(Capture.capturePhoto(width, -1)); | |
Image roundMask = Image.createImage(width, capturedImage.getHeight(), 0xff000000); | |
Graphics gr = roundMask.getGraphics(); | |
gr.setColor(0xffffff); | |
gr.fillArc(0, 0, width, width, 0, 360); | |
Object mask = roundMask.createMask(); | |
capturedImage = capturedImage.applyMask(mask); | |
picture.setIcon(capturedImage); | |
hi.revalidate(); | |
} catch(IOException err) { | |
Log.e(err); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sample usage of Image & Capture.
From the Codename One project