我需要將App圖標加載到圖像視圖中。在列表視圖中加載它太慢了。將可繪製對象載入圖像使用通用圖像加載器或任何一張picasso查看
我試圖使用畢加索或通用圖像加載器加載它。
我無法找到如何使用任何這些庫加載Drawable對象(NOT FROM RESOURCES)到圖像視圖中?
獲取drawable的函數: Drawable icon = p.applicationInfo.loadIcon(getPackageManager());
我需要將App圖標加載到圖像視圖中。在列表視圖中加載它太慢了。將可繪製對象載入圖像使用通用圖像加載器或任何一張picasso查看
我試圖使用畢加索或通用圖像加載器加載它。
我無法找到如何使用任何這些庫加載Drawable對象(NOT FROM RESOURCES)到圖像視圖中?
獲取drawable的函數: Drawable icon = p.applicationInfo.loadIcon(getPackageManager());
使用Picasso
您需要將您的drawable/bitmap轉換爲文件。 Picasso
可以加載圖像文件。
要將位圖/繪圖文件轉換爲文件,請使用此選項。只需將參數從位圖更改爲可繪製。
public static File bitmapToFile(Bitmap bitmap, String fileName) {
try {
File file = File.createTempFile(fileName, ".png");
if (file.exists()) {
file.delete();
}
file.createNewFile();
file.deleteOnExit();
ByteArrayOutputStream bos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 0, bos);
byte[] bitmapData = bos.toByteArray();
FileOutputStream fos = new FileOutputStream(file);
fos.write(bitmapData);
fos.flush();
fos.close();
return file;
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
並加載,你可以這樣做:
File bitmapFile = bitmapToFile(yourBitmap, "aRandomName");
Picasso.with(context).load(bitmapFile).into(imageView);
你可以這樣寫:
Picasso.with(上下文) .load(R.drawable.yourDrawable) .into(ImageView的);在
更多信息:http://square.github.io/picasso/
希望它能幫助。
如果它解決了您的問題,請將其標記爲正確答案。謝謝。 –
可繪製對象(不來自資源) – Rakhiii
您可以使用它的url或resourceId或uri加載圖像。不能用畢加索
Picasso.with(getContext()).load(imageResourceId)
.into(imageView);
直接添加繪製到ImageView的,如果你要調整你的繪製或位圖文件,搜索
如何加載位圖有效
可繪製對象(不來自資源) – Rakhiii
這是我的轉換後的代碼,但如何.. Drawable icon = p.applicationInfo.loadIcon(getPackageManager()); 位圖位圖=((BitmapDrawable)圖標).getBitmap(); – Rakhiii
請給我示例代碼... – Rakhiii
@Rakhiii你在這裏。 –