在将Bitmap转换为byte [] Android时优化图像大小

时间:2014-06-07 16:38:46

标签: android bitmap

我正在为Android构建一个大应用程序,我需要下载并将图像上传到服务器。我使用以下代码进行了转换:

Bitmap bitmap = getBitmapFromGallery();
ByteBuffer buffer = ByteBuffer.allocate(bitmap.getByteCount());
bitmap.copyPixelsToBuffer(buffer);
byte[] result = buffer.array();

但在这种情况下,图像尺寸非常大。我该如何优化呢?

1 个答案:

答案 0 :(得分:0)

You need to start read great tutorial by http://developer.android.com.
But before you have to start i am give you overview of bitmap loader class

- >您应该匹配与设备相同的UI大小 - >您可以使用inSampleSize.来减小图像的大小 - >读取位图尺寸并输入
- >将图像缩小到设备存储器。