Android byte64显着降低了图像质量

时间:2017-03-20 21:22:08

标签: android image base64 decode encode

我已经尝试过在这里发布的各种解决方案,但这些解决方案都没有起作用。

我基本上用相机拍照,将其转换为字节数组,将其放入数据库中,当我想显示图像时,我得到字节数组,解码图像并将其设置为图像视图。但后来我的图像质量比以前差很多。

这是我的编码代码:

 @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == RC_PHOTO_TAKER && resultCode == RESULT_OK) {

        Bitmap selectedImage = (Bitmap) data.getExtras().get("data");
        photoImageView.setImageBitmap(selectedImage);
        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        selectedImage.compress(Bitmap.CompressFormat.JPEG, 100, stream);
        byte[] byteFormat = stream.toByteArray();
        encodedPhoto = Base64.encodeToString(byteFormat, 0);

    }

这是我的解码代码(photoBase64Str1是我从数据库中获得的字符串):

 byte[] decodedString = Base64.decode(photoBase64Str1, Base64.DEFAULT);
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inScaled = false;
        final Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length, options);

        photo1.setImageBitmap(decodedByte);

我尝试过使用Bitmap Factory选项,但没有一个能给我我想要的结果。

0 个答案:

没有答案