码迷,mamicode.com
首页 > 移动开发 > 详细

Android - 确认ImageView的图片是否加载成功

时间:2015-01-14 08:31:14      阅读:209      评论:0      收藏:0      [点我收藏+]

标签:mystra   android   imageview   图片转换   判断图片   

确认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的图片是否加载成功

标签:mystra   android   imageview   图片转换   判断图片   

原文地址:http://blog.csdn.net/caroline_wendy/article/details/42704919

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!