首页 > 代码库 > Android图片转为16进制

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

  

Android图片转为16进制