Android - 确认ImageView的图片是否加载成功
2015-01-14 08:16
393 查看
确认ImageView的图片是否加载成功
本文地址:http://blog.csdn.net/caroline_wendy判断ImageView图片是否存在,未加载成功,就显示默认图片。
if (mPhotoView.getDrawable() == null) { // Toast.makeText(getActivity(), "图片加载失败", Toast.LENGTH_SHORT).show(); mPhotoView.setImageDrawable(getResources().getDrawable(R.drawable.icon_default_user_photo)); }
Android中Bitmap, Drawable, Byte,ID之间的转化
1. Bitmap 转化为 byte
ByteArrayOutputStream out = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.PNG, 100, out); byte[] array= out.toByteArray();
2. byte转化为bitmap
Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
3. bitmap转化为Drawable
Drawable drawable = new FastBitmapDrawable(bitmap);
4. Drawable转化为bitmap
a. BitmapDrawable, FastBitmapDrawable直接用getBitmap
b. 其他类型的Drawable用Canvas画到一个bitmap上
Canvas canvas = new Canvas(bitmap) drawable.draw(canvas)
5.id转化graphic.drawable
Drawable drawable = activity.getResources().getDrawable(R.drawable.icon);
6.id转化成Bitmap
Bitmap bitmap = BitmapFactory. decodeResource (Resources res, int id)
相关文章推荐
- Android - 确认ImageView的图片是否加载成功
- Android - 确认ImageView的图片是否加载成功
- android imageview 加载大图片防止内存溢出的方法
- Android ImageView如何加载网络图片资源
- Android 在onActivityResult()中设置图片setImageResource(resId) 或者改变view属性,不成功的解决办法
- 一句代码加载网络图片到ImageView——Android Picasso
- Android ImageView加载圆形图片且同时绘制圆形图片的外部边缘边线及边框
- android使用ImageView加载本地SdCard图片和加载网络图片
- Android 自定义ImageView加载图片
- Android ListView异步加载图片乱序 使用NetworkImageView
- Android SmartImageView的使用(堪与ImageLoader加载图片媲美)
- Android使用控件ImageView加载图片的方法
- [Android]异步加载图片,内存缓存,文件缓存,imageview显示图片时增加淡入淡出动画
- android控件ImageView加载sdcard卡,网络及res中的图片
- Android - 小功能 使用ImageView加载本地SdCard图片和加载网络图片
- Android ImageView图片浏览器(ImageView加载sd卡图片资源)的内存溢出问题分析
- android ImageView关于网络加载图片圆形处理
- android使用ImageView加载本地SdCard图片和加载网络图片
- Android加载/处理超大图片神器!SubsamplingScaleImageView(subsampling-scale-image-view)【系列1】
- 由于Android列表视图复用到之后的Imageview异步加载图片时候闪烁问题