我正在开发一个独立的Wear应用程序。一切正常但图像加载速度太慢。
我这样做的方式是使用Firebase Storage作为后端。我正在获取网址并使用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);
我正在使用的版本:
这是我将图片上传到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();
}
}
}
答案 0 :(得分: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