Reputation: 35
I've been trying to get the cropped image from ImageViewer when the image is zoomed but when the image is on a corner / border, the returned cropped image isn't the same as the displayed one.
See those images to explain:
Original Image:
ImageViewer (with red background) without zooming or moving:
Returned cropped image :
ImageViewer zoomed to fit the ImageViewer :
Returned cropped image :
ImageViewer zoomed to fit the ImageViewer BUT image is on a border (here the bottom one) and I moved the image up even if I cannot because it's already at the bottom :
Returned cropped image :
It looks like the getCroppedImage doesn't return the displayed image.
Upvotes: 1
Views: 31
Reputation: 52760
I think this is a bug in the pan position rendering. It seems that when we pan this is registered in the component internal state but isn't rendered.
I created a test case and filed an issue here. See the test case below:
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));
});
Upvotes: 0