1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| BufferedImage diff(BufferedImage img1, BufferedImage img2)
{
int w = img1.getWidth();
int h = img1.getHeight();
int[] rgbs1 = new int[w*h];
img1.getRGB(0,0,w,h,rgbs1,0,w);
int[] rgbs2 = new int[w*h];
img2.getRGB(0,0,w,h,rgbs2,0,w);
for (int y = 0; y < h; y++) {
for (int x = 0; x < w; x++) {
int pos = y * h + x;
System.out.print(rgbs1[pos]);
System.out.print("\n");
System.out.print(rgbs2[pos]);
System.out.print("\n");
rgbs1[pos] -= rgbs2[pos];
if (rgbs1[pos] < 0) rgbs1[pos] = 0;
}
}
BufferedImage imgDiff = new BufferedImage(w, h, img1.getType());
imgDiff.setRGB(0,0,w,h,rgbs1,0,w);
return imgDiff;
} |
Partager