我需要将图像转换为十六进制字符串发送到Web服务器。我使用此方法,以图像转换为字节阵列如何将图像转换为android中的十六进制字符串?
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 8;
Bitmap receipt = BitmapFactory.decodeFile(photo.toString(),options);
int size = receipt.getRowBytes() * receipt.getHeight();
ByteArrayOutputStream stream = new ByteArrayOutputStream();
receipt.compress(Bitmap.CompressFormat.JPEG, 90, stream);
receiptbyte = stream.toByteArray();
String hexstring = toHex(receiptbyte);
并且这转换成十六进制
public static String toHex(byte[] bytes) {
BigInteger bi = new BigInteger(1, bytes);
return String.format("%0" + (bytes.length << 1) + "X", bi);
}
我想产生的输出作为像
c11ee236-8f72-4b60-9208-79977d61993f
我不知道该怎么办。我需要对它进行编码吗?
2012-05-15
GoCrazy
+0
看看这个线程:http://stackoverflow.com/questions/1314568/java-file-to-hex –