在我的手机上显示图像时出现问题,但是图像在Android Emulator上显示良好

时间:2019-06-12 15:14:31

标签: android

我使用base 64方法将图像转换为字符串,然后使用改型将其存储在数据库中,并对其进行很好的调用,并在Android模拟器中将其显示,但是在Mobile中将其转换为APK之后见过  apiInterface = login_client.getApiClient()。create(login_interface.class);

    retrofit2.Call<Info> call = apiInterface.getinfo(strimage);
    call.enqueue(new Callback<Info>() {

        @Override
        public void onResponse(Call<Info> call, Response<Info> response) {

            strimage=response.body().getImgnameinfo();
            Toast.makeText(Login_Activity.this, strimage, Toast.LENGTH_SHORT).show();
            imagtest.setImageBitmap(StringToBitMap(strimage));
            imagtest.bringToFront();

        }

        @Override
        public void onFailure(Call<Info> call, Throwable t) {

        }

    });

公共静态位图StringToBitMap(字符串图像){

    try {
        byte[] encodeByte = Base64.decode(image.getBytes(), Base64.DEFAULT);
     final   Bitmap bitmap = BitmapFactory.decodeByteArray(encodeByte, 0,
                encodeByte.length);
        return bitmap;
    } catch (Exception e) {
        e.getMessage();
        return null;
    }
}

1 个答案:

答案 0 :(得分:0)

如果位图大小太大,则图像视图将无法显示。您可以在设置为图像视图之前手动缩放位图以减小尺寸,或使用类似glide的库来加载位图。

Using Glide to set bitmap into an imageview

Load bitmap efficiently