从字符串路径创建位图

Creating bitmap from string path

所以我正在创建位图,使用以下代码:

BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
options.inMutable = true;
return BitmapFactory.decodeFile(photoPath, options);

我的问题是,为什么在某些手机上创建它要花这么多时间? 有什么方法可以在不浪费大量等待时间的情况下创建位图吗? 有小伙伴遇到这个问题吗?任何帮助将不胜感激。

尝试下面的代码片段:

public static Bitmap decodeFile(String photoPath){
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inJustDecodeBounds = true;
        BitmapFactory.decodeFile(photoPath, options);

        options.inJustDecodeBounds = false;
        options.inDither = false;
        options.inPurgeable = true;
        options.inInputShareable = true;
        options.inPreferQualityOverSpeed = true;

        return BitmapFactory.decodeFile(photoPath, options);
}

1) 使用缩小版本的图像,这样可以避免内存和执行时间浪费

2) 尝试异步处理位图。

可以参考http://developer.android.com/training/displaying-bitmaps/index.html