Android图片转为16进制

/**
* 将图片转换成十六进制字符串
* @param photo
* @return
*/
public static String sendPhoto(ImageView photo) {
Drawable d = photo.getDrawable();
Bitmap bitmap=((BitmapDrawable)d).getBitmap();
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);// (0 - 100)压缩文件
byte[] bt = stream.toByteArray();
String photoStr = byte2hex(bt);
return photoStr;


}
/**
* 二进制转字符串
* @param b
* @return
*/
public static String byte2hex(byte[] b)  
{
StringBuilder sb = new StringBuilder();
String stmp = "";
for (int n = 0; n < b.length; n++) {
stmp = Integer.toHexString(b[n] & 0XFF);
if (stmp.length() == 1) {
sb.append("0" + stmp);
} else {
sb.append(stmp);
}


}
return sb.toString();
}

  

posted @ 2014-09-03 18:21  xxdc  阅读(946)  评论(0编辑  收藏  举报