Generate a md5 sum from an Android Bitmap object

落花浮王杯 提交于 2019-12-05 21:35:43

Get bitmap's bytes to calculate md5.

Bitmap bm = ... // your bitmap
ByteArrayOutputStream baos = new ByteArrayOutputStream();  
bm.compress(Bitmap.CompressFormat.PNG, 100, baos); //bm is the bitmap object   
byte[] bitmapBytes = baos.toByteArray();

So you have byte array now. You can find how to get md5 hash of byte array in android here.

I'm not Android developer, but I see in the API reference (http://developer.android.com/reference/android/graphics/Bitmap.html) that there are methods for:

  • getting size of the bitmap: getWidth, getHeight
  • getting the pixels as an array of integers: getPixels

So you could just create an array of needed size, then read all the pixels, and convert the array to byte[].

Then it should be not a problem to calculate md5 sum from it.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!