Android - 确认ImageView的图片是否加载成功
确认ImageView的图片是否加载成功
本文地址:http://blog.csdn.net/caroline_wendy
if (mPhotoView.getDrawable() == null) { // Toast.makeText(getActivity(), "图片加载失败", Toast.LENGTH_SHORT).show(); mPhotoView.setImageDrawable(getResources().getDrawable(R.drawable.icon_default_user_photo)); }
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)
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。