Skip to content

Commit 85f3ea4

Browse files
committed
Fix getPixel on high DPI devices
1 parent 9ec322b commit 85f3ea4

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/main/java/codedraw/Image.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import java.io.*;
99
import java.net.MalformedURLException;
1010
import java.net.URL;
11+
import java.util.Arrays;
1112
import java.util.Base64;
1213

1314
/**
@@ -710,17 +711,17 @@ public Color getPixel(int x, int y) {
710711
int xStart = x * xScale;
711712
int yStart = y * yScale;
712713

713-
for (int xi = xStart; xi < xStart + xScale; xi++) {
714-
for (int yi = yStart; yi < yStart + yScale; yi++) {
715-
argb[xi * xScale + yi] = image.getRGB(xi, yi);
714+
for (int xi = 0; xi < xScale; xi++) {
715+
for (int yi = 0; yi < yScale; yi++) {
716+
argb[xi * xScale + yi] = image.getRGB(xi + xStart, yi + yStart);
716717
}
717718
}
718719

719720
return Palette.fromARGB(
720-
averageColor(argb, 0),
721-
averageColor(argb, 1),
721+
averageColor(argb, 3),
722722
averageColor(argb, 2),
723-
averageColor(argb, 3)
723+
averageColor(argb, 1),
724+
averageColor(argb, 0)
724725
);
725726
}
726727
}

0 commit comments

Comments
 (0)