android 十六进制存储为图片,如何将图像转换为android中的十六进制字符串?

这篇博客介绍了如何在Android中将Bitmap图像转换为十六进制字符串,以便将其发送到Web服务器。首先,使用BitmapFactory解码图片,然后压缩为字节数组,接着通过一个名为`toHex`的方法将字节数组转化为十六进制字符串。作者遇到的问题是如何生成类似UUID的格式,而目前的方法只能得到一串连续的十六进制数。
摘要由CSDN通过智能技术生成

我需要将图像转换为十六进制字符串发送到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 –

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值