生成从Android位图对象的MD5校验和 [英] Generate a md5 sum from an Android Bitmap object

查看:1659
本文介绍了生成从Android位图对象的MD5校验和的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经花了几个小时试图找出如何做到这一点。我已经张贴在这里的计算器和文档阅读后后。

I've spent several hours trying to figure out how to do this. I've read post after post here on stackoverflow and the documentation.

我有一个android.graphics.Bitmap对象,我需要得到它的MD5校验和。在点我想要验证它没有被保存到文件系统的总和。我见过这样的java.io.File对象,在几个方面。我只需要接收一个位图对象,并返回六角MD5校验和作为一个字符串的函数。

I have a android.graphics.Bitmap object and I need to get it's md5 sum. At the point that I want to verify the sum it has not been saved to the file system. I've seen several ways of doing this for java.io.File objects. I just need a function that receives a Bitmap object and returns the hex md5 sum as a String.

这可能是解决的地方,但如果它一直是我一直无法理解,或演绎如何从它做到这一点。

This might have been addressed somewhere but if it has been I have been unable to understand it or deduce how to do it from it.

资源重方法少是更好的当然是。

The less resource heavy the method is the better it is of course.

推荐答案

获取位图的字节来计算MD5。

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();

所以,你必须字节数组现在。你可以找到如何获取字节数组的MD5哈希在android系统这里

这篇关于生成从Android位图对象的MD5校验和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆