Nemuse
Nemuse

Reputation: 35

ImageViewer.getCroppedImage returns the wrong image

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:

Original Image

Example 1:

ImageViewer (with red background) without zooming or moving:

enter image description here

Returned cropped image :

enter image description here

Example 2 (working as expected):

ImageViewer zoomed to fit the ImageViewer :

enter image description here

Returned cropped image :

enter image description here

Example 3:

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 :

enter image description here

Returned cropped image :

enter image description here

It looks like the getCroppedImage doesn't return the displayed image.

Upvotes: 1

Views: 31

Answers (1)

Shai Almog
Shai Almog

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

Related Questions