-
Enhancement
-
Resolution: Duplicate
-
P4
-
None
-
8, 9, 10
-
generic
-
generic
A DESCRIPTION OF THE REQUEST :
When drawing pixelated Images on a Canvas with a given width/height, they can only be drawn with Interpolation, which is not always what the developer wants. There is a workarounds by doing this yourself with PixelReader/Writer, but it performs very poorly.
JUSTIFICATION :
The developer sometimes Needs Control (like in Swing, or HTML5) about the interpolation method, or if it should be disabled. I.e. useful in 2D-Gamedev.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
An ability to turn off Interpolation, the resulting Image drawn with a different resolution on a canvas should be pixelated.
ACTUAL -
The Image is always smoothed out.
---------- BEGIN SOURCE ----------
Image image = ...;
canvas.setWidth(scale * width);
canvas.setHeight(scale * height);
GraphicsContext gc = canvas.getGraphicsContext2D();
gc.drawImage(image, 0, 0, scale * width, scale * height);
// this gives same result
// gc.scale(scale, scale);
// gc.drawImage(editableImage, 0, 0, width, height);
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
PixelReader reader = image.getPixelReader();
PixelWriter writer = gc.getPixelWriter();
for (int y = 0; y < scale * height; ++y) {
for (int x = 0; x < scale * width; ++x) {
writer.setArgb(x, y, reader.getArgb(x / scale, y / scale));
}
}
Performs poorly and doesn't Support Transparent Pixels drawn over each other.
When drawing pixelated Images on a Canvas with a given width/height, they can only be drawn with Interpolation, which is not always what the developer wants. There is a workarounds by doing this yourself with PixelReader/Writer, but it performs very poorly.
JUSTIFICATION :
The developer sometimes Needs Control (like in Swing, or HTML5) about the interpolation method, or if it should be disabled. I.e. useful in 2D-Gamedev.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
An ability to turn off Interpolation, the resulting Image drawn with a different resolution on a canvas should be pixelated.
ACTUAL -
The Image is always smoothed out.
---------- BEGIN SOURCE ----------
Image image = ...;
canvas.setWidth(scale * width);
canvas.setHeight(scale * height);
GraphicsContext gc = canvas.getGraphicsContext2D();
gc.drawImage(image, 0, 0, scale * width, scale * height);
// this gives same result
// gc.scale(scale, scale);
// gc.drawImage(editableImage, 0, 0, width, height);
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
PixelReader reader = image.getPixelReader();
PixelWriter writer = gc.getPixelWriter();
for (int y = 0; y < scale * height; ++y) {
for (int x = 0; x < scale * width; ++x) {
writer.setArgb(x, y, reader.getArgb(x / scale, y / scale));
}
}
Performs poorly and doesn't Support Transparent Pixels drawn over each other.
- duplicates
-
JDK-8204060 [Canvas] Add API in GraphicsContext to control image smoothing
-
- Resolved
-