我对毕加索不太熟悉,但我的应用程序使用它来从其URL中加载图像。
但是我想制作一个按钮,当它被点击时,它会将图像标记为收藏夹,即使在脱机状态下也会显示它。
我正在用Content Provider保存其他东西(字符串,双打)。
所以,我认为最好的方法是保存图像以显示即使离线。
但是,如何保存它们?如何使用毕加索保存和显示图像
0
A
回答
0
下载带有网址的图片还有一个不错的选择。试试这个代码。
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
new DownloadFile().execute("https://i.stack.imgur.com/w4kCo.jpg");
}
class DownloadFile extends AsyncTask<String,Integer,Long> {
ProgressDialog mProgressDialog = new ProgressDialog(MainActivity.this);// Change Mainactivity.this with your activity name.
String strFolderName;
@Override
protected void onPreExecute() {
super.onPreExecute();
mProgressDialog.setMessage("Downloading Image ...");
mProgressDialog.setIndeterminate(false);
mProgressDialog.setMax(100);
mProgressDialog.setCancelable(false);
mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
mProgressDialog.show();
}
@Override
protected Long doInBackground(String... aurl) {
int count;
try {
URL url = new URL((String) aurl[0]);
URLConnection conexion = url.openConnection();
conexion.connect();
String targetFileName="downloadedimage.jpg";//Change name and subname
int lenghtOfFile = conexion.getContentLength();
String PATH = Environment.getExternalStorageDirectory()+"/myImage/";
File folder = new File(PATH);
if(!folder.exists()){
folder.mkdir();//If there is no folder it will be created.
}
InputStream input = new BufferedInputStream(url.openStream());
OutputStream output = new FileOutputStream(PATH+targetFileName);
byte data[] = new byte[1024];
long total = 0;
while ((count = input.read(data)) != -1) {
total += count;
publishProgress ((int)(total*100/lenghtOfFile));
output.write(data, 0, count);
}
output.flush();
output.close();
input.close();
} catch (Exception e) {}
return null;
}
protected void onProgressUpdate(Integer... progress) {
mProgressDialog.setProgress(progress[0]);
if(mProgressDialog.getProgress()==mProgressDialog.getMax()){
mProgressDialog.dismiss();
Toast.makeText(getApplicationContext(), "Download Completed !", Toast.LENGTH_LONG).show();
}
}
protected void onPostExecute(String result) {
}
}
并将下载的图像位图设置为Imageview。
0
这是代码。通过这种策略,毕加索将在缓存中查找图像,如果失败,则图像将通过网络下载。
Picasso.with(context)
.load(Uri.parse(getItem(position).getStoryBigThumbUrl()))
.networkPolicy(NetworkPolicy.OFFLINE)
.into(holder.storyBigThumb, new Callback() {
@Override
public void onSuccess() {
}
@Override
public void onError() {
// Try again online if cache failed
Picasso.with(context)
.load(Uri.parse(getItem(position)
.getStoryBigThumbUrl()))
.placeholder(R.drawable.user_placeholder)
.error(R.drawable.user_placeholder_error)
.into(holder.storyBigThumb);
}
});
毕加索有自己的缓存你不会需要自己处理任何东西。
相关问题
- 1. 毕加索图像缓存
- 2. 保存图像在SD卡后毕加索加载图像
- 3. 使用毕加索时,我还需要保存图像吗?
- 4. 毕加索图书馆是否将图像保存到缓存?
- 5. 如何显示)popBackStack(后载有毕加索图像
- 6. 毕加索 - 当图像保存到磁盘时显示吐司/消息
- 7. 使用毕加索和回收站视图来显示图像列表
- 8. 将图像从毕加索保存到内存
- 9. 毕加索图书馆和GridView图像
- 10. 毕加索为什么不保存图像缓存供脱机使用?
- 11. 如何使用毕加索
- 12. 如何使用毕加索
- 13. 加载毕加索的图像并不总是显示
- 14. 毕加索重复图像
- 15. 如何从毕加索在位图变量中存储图像
- 16. 使用毕加索加载图像时保持图像的纵横比?
- 17. 毕加索和图像大小
- 18. 毕加索图像加载以前缓存图像
- 19. 毕加索和Firebase存储
- 20. 如何显示,而无需使用Android的毕加索
- 21. 毕加索在appwidget中使用缓存图像的数据
- 22. 毕加索不会显示imgur的图像
- 23. 图像没有显示在毕加索,因为gridview
- 24. 与OKHttp不显示图像的毕加索:日志错误
- 25. Android的显示图像的GridView从URL与毕加索
- 26. 毕加索不显示图像的自定义链接Android
- 27. 如何使用毕加索从mp3文件设置图像
- 28. 如何存储由毕加索在android下载的图像?
- 29. 图片不显示使用毕加索在android
- 30. 用毕加索覆盖图像