androidimageviewgetpixel

compare 2 images to avoid duplication


I am comparing 2 similar images and would like to see if both are similar .Currently I used the code:

public void foo(Bitmap bitmapFoo) {
    int[] pixels;

    int height = bitmapFoo.getHeight();
    int width = bitmapFoo.getWidth();

    pixels = new int[height * width];

    bitmapFoo.getPixels(pixels, 0, width, 1, 1, width - 1, height - 1); 


}

and I call the function : foo(img1) where :

img1=(Bitmap)data.getExtras().get("data");

I would like to know how to get the above getpixel,I tried assigning it to variable but did not work .Should it have a return type ?? and in format it is ?

And also how do I compare 2 images??

Also both the images may be of different dimensions based on the mobile camera the snapshot is taken from .

Also can it recognize if the same image is shot in the morning and night ???

Thanks in Advance.


Solution

  • If you want to copy the pixels of the bitmap to a byte array, the easiest way is:

    int height = bitmapFoo.getHeight();
    int width = bitmapFoo.getWidth();
    
    pixels = new int[height * width];
    
    bitmapFoo.copyPixelsToBuffer(pixels);
    

    See the documentation

    I should warn you that you will have to handle this with care, any other way you will get OutOfMemoryError.

    To get All Pixels

    bitmapFoo.copyPixelsToBuffer(pixels);
    

    or

    bitmapFoo.getPixels(pixels, 0, width, 0, 0, width, height);
    

    To get One Pixel

    The two arguments must be two integers within the range [0, getWidth()-1] and [0, getHeight()-1]

    int pix = bitmapFoo.getPixel(x, y);