我们如何编码和解码图像字符串数据并在imageview上显示

时间:2013-11-12 05:01:08

标签: android

我正在获取图像的解码字符串数据,我想编码该数据并在图像视图上显示。我在位图中得到空值。

这就是我到目前为止所做的。

@SuppressLint("NewApi")
public void show(View view){ 
     byte[] imageBytes = null;
    try {
        imageBytes = imagedata.getBytes("UTF-8");
    break;
// here you could place handling of other clicks if necessary...        
    } catch (UnsupportedEncodingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
        InputStream in = new ByteArrayInputStream(imageBytes);
        Bitmap b = BitmapFactory.decodeStream(in);
         image.setImageBitmap(b);

}

1 个答案:

答案 0 :(得分:0)

解码图像使用以下代码:

byte[] decodedString = Base64.decode(image_path, Base64.DEFAULT);
Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length, options);
// options.inJustDecodeBounds = false;
promoIV.setImageBitmap(decodedByte);