如何在Android Wear独立应用程序中将URL加载到ImageView中?

问题描述 投票:0回答:1

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

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

我也尝试使用毕加索同样的结果。

我试图使用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);

我正在使用的版本:

  • Gradle:3.0.1
  • Google服务: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();
        }
    }
}
android performance picasso android-glide android-wear-2.0
1个回答
0
投票

我发现了这个问题。感谢Akshay Katariya的时间!

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

我在独立佩戴应用程序中使用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

© www.soinside.com 2019 - 2024. All rights reserved.