[英]How to load URL into ImageView in a Android Wear Standalone App?
我正在開發一個獨立的Wear應用。 一切正常,但是圖像加載太慢。
我這樣做的方法是使用Firebase Storage作為后端。 我正在獲取URL並使用Glide將其加載到ImageView
。
我也嘗試使用具有相同結果的畢加索。
我嘗試使用達芬奇圖書館,但是它太舊了(3歲)。 我點擊了此鏈接: 如何在Android Wear中加載URL圖片?
我使用的代碼非常簡單:
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();
}
}
}
我發現了問題。 感謝Akshay Katariya的寶貴時間!
我感到as愧,因為這是我身邊的一個愚蠢的錯誤。 在下載圖像之前,我正在創建一個位圖並將其設置到ImageView中。 無論如何,現在它可以完美地工作,因此這是我的代碼完全可以對可能嘗試實現它的任何人起作用。
我在獨立Wear應用程序中使用Picasso和Firebase Storage:
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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.