导入包(http://download.csdn.net/detail/s1e1s/9066317和http://download.csdn.net/detail/s1e1s/9066317)
为了使用universal-image-loaderjar包,可以在自定义Application类中实现下面的方法
private void initImagloader(Context context) {
//获取缓存的路径
File cacheDir = StorageUtils.getOwnCacheDirectory(context,
"photoview/Cache");
//配置Inageload
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(
context)
//线程池内加载的数量
.discCache(new UnlimitedDiscCache(cacheDir)) //设置硬盘缓存
.threadPoolSize(3).threadPriority(Thread.NORM_PRIORITY - 2)
.memoryCache(new WeakMemoryCache())
.denyCacheImageMultipleSizesInMemory()
.discCacheFileNameGenerator(new Md5FileNameGenerator())
//保存的时候的URL用MD5加密
.tasksProcessingOrder(QueueProcessingType.LIFO)
.discCache(new UnlimitedDiscCache(cacheDir))//自定义缓存路径
// .defaultDisplayImageOptions(DisplayImageOptions.createSimple())
.writeDebugLogs() // Remove for release app
.build();
// Initialize ImageLoader with configuration.
ImageLoader.getInstance().init(config);//全局初始化此设置
}
//uk.co.senab.photoview.PhotoView
iv_photo = (PhotoView) findViewById(R.id.iv_photo);
//当iv_photo为ImageView时使用PhotoViewAttacher封装
//attacher = new PhotoViewAttacher(iv_photo);
//加载本地图片
try {
//从assets中获取资源文件的输入流
InputStream is = getAssets().open("photoview.jpg");
//从输入流构建Bitmap对象
Bitmap bm = BitmapFactory.decodeStream(is);
iv_photo.setImageBitmap(bm);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//加载网络图片
loader = ImageLoader.getInstance();
loader.displayImage("http://e.hiphotos.baidu.com/image/pic/item/ca1349540923dd547212ee69d309b3de9c824849.jpg", iv_photo);