From: Thomas J. <ntm...@gm...> - 2005-05-20 21:22:46
|
On 5/19/05, he...@sf... <he...@sf...> wrote: > Example: Comparing only without "BufferedImage@e2cb55:" @e2cb55 is the > buffered image's memory location right? According to http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Object.html#= toString() the default toString() method (implicitly called on non-String objects when you print them) outputs the class name and the hash code of the object being printed. By the looks of it, hashcode()'s default implementation will return the address of the object in question. It is worth noting that it is not always possible to rely on this fact, as the default hashcode() is implementation-dependant, and may vary between implementations of the Java Virtual Machine. > If I only use m.getImage().getdata() then I just receive line2's info, so= if > I required to compare A's line 1&2 with B'line1&2 in order to proove the = two > image are equal, then getdata is insufficient(imcomplete), because it lef= t > out some data. This is correct. > In sum, let's recap. the problem: compare line 2 only to proove two buffe= red > image equal? >=20 > Yes (error) or No (.tostring and stringtokenizer consideration)? It might take a bit more than just comparing the output of toString() to determine the equality of two images. In reference to the following cohe from TheMatrixTest.java:811 rev 1.13 assert m.getImage().getData() =3D=3D bufferedImage.getData(); First off, I think it's worth asking what kind of equality you're trying to provide here. For objects, the =3D=3D operator compares whether two variables refer to the same object. It's a bit like saying that my name's Thomas, but I'm also referred to as NTmatter -- The names Thomas and NTmatter are for the same object. Contrast this to my (fictional) identical twin, Trevor, who is completely identical to me in all ways, but is a different object altogether. This means that Trevor =3D=3D Thomas is false in all cases, even though Trevor.equals(Thomas) might return true. The distinction between objects and primitives is important, as =3D=3D compares the actual values for primitives. eg, int One =3D 1; int Won =3D 1; One =3D=3D Won is true, because One and Won hold the same value, even though they're stored in different locations in memory. In the present test case, it is pretty much guaranteed that m's image data is not going to be the same data as the BufferedImage's data, as they'll have gone and loaded their image data into seperate Rasters. Raster1 !=3D Raster2. If you're looking for a pixel-by-pixel or component-wise equality (Thomas same as Trevor), then you might want to try a different approach. Fortunately, the java.awt.image.Raster class provides several methods that will be of use to you. Namely, the get{Bands,Width,Height,Pixel,Sample} methods all provide primitive data that can be easily compared by means of the =3D=3D operator. |