【问题标题】:There is a problem displaying the image on my mobile, but the image is well displayed on Android Emulator在我的手机上显示图像时出现问题,但图像在 Android 模拟器上显示良好
【发布时间】:2019-06-12 15:14:31
【问题描述】:

我使用base 64的方法将图像转换成字符串,然后使用retrofit将其存储在数据库中并调用它并在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) {

        }

    });

public static Bitmap StringToBitMap(String image) {

    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;
    }
}

【问题讨论】:

  • 您能提供更多信息吗?例如,您的模拟器中的 android 版本以及您正在测试的手机上的 android 版本。此外,您在AndroidManifiest.xml 文件中将以下权限添加到&lt;uses-permission android: name = "android.permission.READ_EXTERNAL_STORAGE" /&gt;&lt;uses-permission android: name = "android.permission.WRITE_EXTERNAL_STORAGE" /&gt;

标签: android


【解决方案1】:

如果位图尺寸太大,图像视图将无法显示。您可以在设置到 imageview 之前手动缩放位图以减小尺寸,或者使用滑翔等库来加载位图。

Using Glide to set bitmap into an imageview

Load bitmap efficiently

【讨论】:

  • 不,很遗憾
  • 图片尺寸小
  • 我使用了您的代码,但仍然无法在移动设备上显示。
  • 图像大小在内存和分辨率方面是多少?
  • 使用这个来获取大小int bitmapByteCount=BitmapCompat.getAllocationByteCount(bitmap)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-08-17
  • 1970-01-01
  • 2013-05-13
  • 2012-06-25
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多