Replies: 3 comments 9 replies
-
|
I'm not 100% sure if it is applicable to you use-case but if you want a certain "pixel perfect" part of your image, why don't you extract the required part at the |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
|
New snippet: import java.io.*;
import java.nio.file.*;
import java.nio.file.Path;
import org.eclipse.swt.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.widgets.*;
public class AutoscaleImageTest {
public static void main(String[] args) throws IOException {
final Display display = new Display();
final ImageData imageData = getImageDataNotNull("image.png");
System.out.println(imageData.width + "x" + imageData.height);
final ImageData imageData2x = getImageDataNotNull("image-2.png");
final Image image = new Image(display, (ImageDataProvider)zoom -> {
if (zoom == 100) {
return imageData;
}
if (zoom == 200) {
return imageData2x;
}
return null;
});
final Shell shell = new Shell(display);
shell.addListener(SWT.Paint, event -> {
event.gc.drawImage(image,
0, 0, 24, 24,
10, 10, 24, 24);
event.gc.drawImage(image, 100, 10);
});
shell.setSize(200, 100);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
image.dispose();
display.dispose();
}
private static ImageData getImageDataNotNull(String path) throws IOException {
try (InputStream inputStream = Files.newInputStream(Path.of(path))) {
return new ImageData(inputStream);
}
}
}images.zip How can I tell the 9-argument |
Beta Was this translation helpful? Give feedback.


Uh oh!
There was an error while loading. Please reload this page.
-
We have created a lot of images in our applications that contains of rows and columns of subimages. Depending on some state we want to draw the right subimage. Code to reproduce:
Images: files.zip
When running on Linux (Linux Mint, Gnome 48, 2 monitors: 4k and FullHD) with 200% zoom and 100% zoom I get following results:
When I change the screen zooming to 225% and 125% and launch again, I'm getting:
How to correctly draw pixel-exactly defined parts of the original image to the screen? Note, that the the
*-2.pngis just a high-resolution variant of the other.Beta Was this translation helpful? Give feedback.
All reactions