CodenameOne
CodenameOne copied to clipboard
Pan of ImageViewer is saved in internal state and exposed via getCroppedImage()
When panning an ImageViewer the image doesn't move in the UI but the pan does change the image state. As a result the getCroppedImage() results suddenly become "flaky". This is discussed here.
I created the following test case:
Form hi = new Form("Crop", new GridLayout(2, 1));
hi.setScrollable(false);
Image greenImage = Image.createImage(400, 400, 0xff00ff00);
Graphics g = greenImage.getGraphics();
g.setColor(0xffffff);
g.drawLine(0, 0, 400, 400);
g.drawLine(400, 0, 0, 400);
final ImageViewer iv = new ImageViewer(greenImage);
Style ivStyle = iv.getAllStyles();
ivStyle.setBgTransparency(255);
ivStyle.setBgColor(0xff);
Label cropPreview = new Label();
hi.addAll(iv, cropPreview);
hi.show();
UITimer.timer(1000, true, () -> {
cropPreview.setIcon(iv.getCroppedImage(0xff0000));
});
The first screenshot shows the default state which seems correct to me, the second screenshot shows a zoom and left pan. Notice that the pan is rendered to the screenshot but ignored by the image viewer. To zoom in the simulator switch out of single window mode and ctrl-right mouse button drag from top left to bottom right.