Android-Confirm that the ImageView picture is loaded successfully

Source: Internet
Author: User

confirm that the ImageView picture is loaded successfully


This address: Http://blog.csdn.net/caroline_wendy


To determine if the ImageView picture exists and is not loaded successfully, the default picture is displayed.

      if (mphotoview.getdrawable () = = null) {//            Toast.maketext (getactivity (), "Picture loading Failed", Toast.length_short). Show ();            Mphotoview.setimagedrawable (Getresources (). getdrawable (R.drawable.icon_default_user_photo));        }


conversion between bitmap, drawable, Byte,id in Android
1. Convert Bitmap to Byte
Bytearrayoutputstream out = new Bytearrayoutputstream (); Bitmap.compress (Bitmap.CompressFormat.PNG, +, out); byte[] Array= Out.tobytearray ();

2. Convert byte to bitmap
Bitmap Bitmap = bitmapfactory.decodebytearray (data, 0, data.length);

3. Bitmap converted to drawable
drawable drawable = new fastbitmapdrawable (bitmap);

4. drawable converted to bitmap
A. bitmapdrawable, fastbitmapdrawable directly with Getbitmap
B. Other types of drawable using canvas to draw on a bitmap
      Canvas canvas = new Canvas (bitmap)      Drawable.draw (canvas)

5.id Conversion graphic.drawable
drawable drawable = Activity.getresources (). getdrawable (R.drawable.icon);

6.id into bitmap
Bitmap Bitmap = bitmapfactory. Decoderesource (Resources   res, int id)


Android-Confirm that the ImageView picture is loaded successfully

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.