Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import android.graphics.Bitmap;

public class Main {
    /**
     * calculate hashcode for a bitmap.
     * all pixels in the bitmap is considered for the hashcode, and if you want
     * a better performance for the calculation, use {@link #bitmap2hash(Bitmap)}.
     * @return hash code
     */
    public static long bitmap2hashFull(Bitmap bitmap) {
        if (bitmap == null)
            return 0;
        long hash = 31;
        for (int x = 0; x < bitmap.getWidth(); x++) {
            for (int y = 0; y < bitmap.getHeight(); y++) {
                hash *= (bitmap.getPixel(x, y) + 31);
            }
        }
        return hash;
    }
}