【发布时间】:2015-12-18 11:38:43
【问题描述】:
我正在使用以下代码创建位图:
public Bitmap getBitmapFromURL(String src) {
try {
URL url = new URL(src);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoInput(true);
connection.connect();
InputStream input = connection.getInputStream();
Bitmap myBitmap = BitmapFactory.decodeStream(input);
return bitmap;
} catch (Exception e) {
// Log exception
return null;
}
但是,加载需要更多时间。 我想知道毕加索图书馆有可能吗?
到目前为止,我已经尝试过如下使用毕加索:
public Bitmap getBitmapFromURL(String src) {
try {
Picasso.with(this)
.load(src)
.placeholder(R.mipmap.ic_launcher).into(image);
image.setDrawingCacheEnabled(true);
image.buildDrawingCache();
Bitmap bitmap = image.getDrawingCache();
return bitmap;
} catch (Exception e) {
// Log exception
return null;
}
在哪里,
image 是我在 xml 布局中的 imageview。 问题是我不必显示或显示 ImageView,如果可能的话,我必须使用 Picasso 库直接为其生成 Bitmap。
还有一件事要说的是,我无法通过 Picasso 使用上述方式执行代码。它给了我错误非法状态异常。
【问题讨论】:
标签: android android-studio bitmap imageview picasso