Android and android Official Website
Check whether the image of ImageView is successfully loaded.
Address: http://blog.csdn.net/caroline_wendy
JudgmentImageView ImageWhether the image exists. If the image is not loaded successfully, the default image is displayed.
If (mPhotoView. getDrawable () = null) {// Toast. makeText (getActivity (), "image loading failed", Toast. LENGTH_SHORT ). show (); mPhotoView. setImageDrawable (getResources (). getDrawable (R. drawable. icon_default_user_photo ));}
Conversion between Bitmap, Drawable, Byte, and ID in Android
1. Bitmap is converted to byte
ByteArrayOutputStream out = new ByteArrayOutputStream();bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);byte[] array= out.toByteArray();
2. byte conversion to bitmap
Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
3. bitmap conversion to Drawable
Drawable drawable = new FastBitmapDrawable(bitmap);
4. Drawable conversion to bitmap
A. BitmapDrawable and FastBitmapDrawable use getBitmap directly
B. Draw other types of Drawable TO A bitmap Using Canvas.
Canvas canvas = new Canvas(bitmap) drawable.draw(canvas)
5. id conversion graphic. drawable
Drawable drawable = activity.getResources().getDrawable(R.drawable.icon);
6. Convert id to Bitmap
Bitmap bitmap = BitmapFactory. decodeResource (Resources res, int id)