为什么使用 Android Picasso 库下载图片? [英] Why use Android Picasso library to download images?

查看:14
本文介绍了为什么使用 Android Picasso 库下载图片?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么我应该通过 Picasso 库下载图像而不是仅使用此代码:

Why should I download the images via the Picasso library instead of just using this code:

private Bitmap DownloadImage(String URL) 
{
    Bitmap bitmap = null; 
    InputStream in = null; 

    try 
    {
        in = OpenHttpGETConnection(URL);
        bitmap = BitmapFactory.decodeStream(in); in.close();
    } 
    catch (Exception e) 
    {
        Log.d("DownloadImage", e.getLocalizedMessage());
    }

    return bitmap; 
}

另一个问题:

Picasso 是在 UI 中还是通过后台线程下载图像?

Does Picasso download the image in the UI or by background thread?

推荐答案

仅供 Android 新用户或从 iOS 迁移到 Android 的任何人的记录.........

Just for the record for anyone new to Android or perhaps moving to Android from iOS ..........

老实说,就是这么简单.优势令人难以置信.

Honestly, it's that simple. The advantages are unbelievable.

就是这么简单:

Picasso.
  with(State.mainContext).
  load(parseImageFile.getUrl()).
  into(null);

你很简单:

就是这么简单.除非您想从头开始编写,否则您必须使用毕加索.

It's that simple. Unless you want to write that from scratch, you simply must use Picasso.

请注意,ParseImageFile 基本上不起作用 - 它对缓存等完全无用.Picasso 有令人钦佩的替代品(例如 Universal Image Loader,请查看),但目前 2014 年没有一款能像 Picasso 一样有效.

Note that ParseImageFile essentially doesn't work - it is utterly useless about caching and so on. There are admirable alternatives to Picasso (such as Universal Image Loader, check it out), but none work as well as Picasso, for now 2014.

注意如果你转向超级高级的东西......唯一比毕加索更好的事情就是转向排球.但这是一个巨大的飞跃.

Note if you move to super-advanced-stuffs... The only thing better than Picasso, is to make the move to Volley. but that is a huge leap.

请注意,Android 上的 ListView 滚动比 iOS 上的表格处理滚动问题要多得多.你可以说,Android + Picasso 更像是 iOS 上的情况,在那里所有的工作都已经完成了滚动带有图像的大表格视图.

Note that ListView scrolling on android is much, much more problematic than table handling scrolling on iOS. You could say, Android + Picasso is MORE LIKE the situation on iOS, where all the work is already done for scrolling large table views with images.

就今天而言,毕加索是任何 Android 应用程序的核心部分.谢天谢地,这是一行代码 - 没有设置,什么都没有.

For today, Picasso is - simply - a central part of any Android app whatsoever. Thank goodness, it is one line of code - no setup, nothing.

再说一次,唯一比"更好的是如果你转向 Volley,毕加索就是这样.

Again, the only thing "better than" Picasso is if you move to Volley.

顺便说一句,这里有一篇关于 Volley v. Picasso 的优秀长文,如果你需要的话......

BTW here's an excellent long article on Volley v. Picasso, if you need that...

http://www.bignerdranch.com/blog/solving-the-android-image-loading-problem-volley-vs-picasso/

这篇关于为什么使用 Android Picasso 库下载图片?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆