专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > 图形/图像

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

发布时间:2011-06-27 19:36:48 文章来源:www.iduyao.cn 采编人员:星星草
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)




友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: