0

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

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

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

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

我使用的代码非常简单:

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

和滑翔版本:

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

我正在使用的版本:

  • 摇篮:3.0.1
  • 谷歌服务: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();
        }
    }
}
4

1 回答 1

0

我发现了这个问题。感谢 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

于 2018-03-27T12:22:22.017 回答