Android-confirm whether the ImageView image is successfully loaded

Source: Internet
Author: User

Android-confirm whether the ImageView image is successfully loaded
Check whether the image of ImageView is successfully loaded.

 

 

 

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)


 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.