publicboolean compare() throws Exception
{ if (m_img1 == null || m_img2 == null)
{ thrownew Exception("Only one image captured!");
} boolean ret = true; int w1 = m_img1.getWidth(); int h1 = m_img1.getHeight(); int w2 = m_img2.getWidth(); int h2 = m_img2.getHeight();
if (w1 != w2 || h1 != h2)
{
System.out.println("### 1\n"); //Different size. Create an image that holds both images. int w = w1 > w2 ? w1 : w2; int h = h1 > h2 ? h1 : h2;
m_imgDiff = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); for (int y = 0; y < h; y ++)
{ for (int x = 0; x < w; x++)
{ boolean bOutOfRange = false; int pixel1 = 0; int pixel2 = 0; //get the pixel for m_img1 if (x < w1 && y < h1)
{
pixel1 = m_img1.getRGB(x, y);
} else
{
bOutOfRange = true;
}
if (x < w2 && y < h2)
{
pixel2 = m_img2.getRGB(x, y);
} else
{
bOutOfRange = true;
}
if (bOutOfRange || pixel1 != pixel2)
{
m_imgDiff.setRGB(x, y, m_diffColor);
} else
{
m_imgDiff.setRGB(x, y, pixel1);
}
}
} returnfalse;
}
//Images have same dimension int[] pixels1 = newint[w1 * h1];
PixelGrabber pg = new PixelGrabber(
m_img1.getSource(), 0, 0, w1, h1, pixels1, 0, w1);
pg.grabPixels();
m_imgDiff = new BufferedImage(w1, h1, BufferedImage.TYPE_INT_ARGB);
//First check if the images differ. int lenAr = pixels1.length; int index = 0; for (index = 0; index < lenAr; index++)
{ if (pixels1[index] != pixels2[index])
{ break;
}
}
//If the images are different, then create the diff image if (index < lenAr)
{ for (int y = 0; y < h1; y++)
{ for (int x = 0; x < w1; x++)
{ int offset = y * w1 + x; if (pixels1[offset] != pixels2[offset])
{
ret = ret && false;
m_imgDiff.setRGB(x, y, m_diffColor);
} else
{
m_imgDiff.setRGB(x, y, pixels1[offset]);
}
}
}
} return ret;
}
/** Writes Images to a location. The *directoryisdeterminedbythejavapropertyOOoBean.Images *
*/ publicvoid writeImages() throws Exception
{
String imgLocation = System.getProperty("OOoBean.Images", "");
File file_tmp = File.createTempFile("OOoBean", "", new File(imgLocation));
File file1 = new File(file_tmp.getPath()+".png");
file_tmp.delete(); if (m_img1 != null)
{
ImageIO.write(m_img1, "png", file1);
System.out.println("\nCompared images:");
System.out.println("1. " + file1.getPath());
}
file1= null;
file_tmp= null;
file_tmp = File.createTempFile("OOoBean", "", new File(imgLocation));
file1 = new File(file_tmp.getPath()+".png");
file_tmp.delete(); if (m_img2 != null)
{
ImageIO.write(m_img2, "png", file1);
System.out.println("2. " + file1.getPath());
}
file1= null;
file_tmp= null;
file_tmp = File.createTempFile("OOoBean", "_diff", new File(imgLocation));
file1 = new File(file_tmp.getPath()+".png");
file_tmp.delete(); if (m_imgDiff != null)
{
ImageIO.write(m_imgDiff, "png", file1);
System.out.println("Diff image: " + file1.getPath() + "\n");
}
}
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.14 Sekunden
(vorverarbeitet am 2026-09-28)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.