【问题标题】:How to load URL into ImageView in a Android Wear Standalone App?如何在 Android Wear 独立应用程序中将 URL 加载到 ImageView 中?
【发布时间】:2018-03-27 11:12:00
【问题描述】:

我正在开发一个独立的 Wear 应用。一切正常,但图像加载太慢。

我这样做的方式是使用 Firebase 存储作为后端。我正在获取 URL 并使用 Glide 将其加载到 ImageView

我也尝试使用 Picasso 获得相同的结果。

我尝试使用 DaVinci 库,但它太旧了(3 岁)。我点击了这个链接:How to load URL image in android wear?

我使用的代码很简单:

Picasso.get().load(imageUrl).into(iv);

和 Glide 版本:

Glide.with(iv.getContext()).load(imageUrl).into(iv);

我正在使用的版本:

  • 分级:3.0.1
  • Google-services:3.2.0/ 11.8.0 用于依赖项
  • 滑翔:4.3.1
  • 毕加索:2.71828

这是我将图像上传到 Firebase-Storage 的方式:

String filePath = photoFile.getAbsolutePath();
Bitmap bitmap = BitmapFactory.decodeFile(filePath, options);
mFormActivity.getContentResolver().notifyChange(photoURI, null);
int rotateImage = getCameraPhotoOrientation(filePath);

Matrix matrix = new Matrix();
matrix.postRotate(rotateImage);
Bitmap rotatedBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);

FileOutputStream fos = null;
try {
    fos = new FileOutputStream(photoFile);
    rotatedBitmap.compress(Bitmap.CompressFormat.PNG, 25, fos);
    fos.close();
} catch (IOException e) {
    Log.d(TAG, "fixLandscapeOrientationCamera.error = " + e.toString());
    if (fos != null) {
        try {
            fos.close();
        } catch (IOException e1) {
            e1.printStackTrace();
        }
    }
}

【问题讨论】:

  • 您的图像在分辨率和 MB / KB 大小方面有多大,这对于 Android 可穿戴设备显然很重要。
  • 嗨!图片大小为 80-90Kb....它们是个人资料图片。我正在使用相机意图
  • 相机意图用于??
  • 不不...对不起!!你是对的......相机拍摄的是4Mb!我会马上改变它,但模拟用户有 80-90Mb 的图像,它仍然很慢
  • 你需要实现一些优化和压缩技术developer.android.com/topic/performance/graphics/…

标签: android performance picasso android-glide android-wear-2.0


【解决方案1】:

我发现了问题。感谢 Akshay Katariya 抽出宝贵时间!!

我感到很惭愧,因为这是我身边的一个愚蠢的错误。在下载图像之前,我正在创建一个位图并将其设置到 ImageView 中。无论如何,现在它工作得很好,所以这是我的代码完全适用于任何可以尝试实现它的人。

我在一个独立的 Wear 应用中使用 Picasso 和 Firebase 存储:

StorageReference imageReference = App.getStorage().getReference().child("images/" + mUser.getPicture());
imageReference.getDownloadUrl()
        .addOnSuccessListener(uri -> {
            Log.d("Testing", "loadSuggestionFace: setting the image");
            Picasso.get().load(uri.toString()).into(mFace1ProfilePicture);
        })
        .addOnFailureListener(exception -> Log.d(TAG, "getDownloadUrl.addOnFailureListener: error = " + exception.toString()));

应用它的类扩展我正在初始化 Firebase 的应用程序

mUser.getPicture() 包含文件名(例如 carlos.png)

mFace1ProfilePicture 它的 ImageView

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-04
    • 1970-01-01
    • 2023-02-17
    • 1970-01-01
    • 1970-01-01
    • 2011-01-29
    相关资源
    最近更新 更多