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
2. byte轉化為bitmap
3. bitmap轉化為Drawable
4. Drawable轉化為bitmap
a. BitmapDrawable, FastBitmapDrawable直接用getBitmap
b. 其他類型的Drawable用Canvas畫到一個bitmap上
5.id轉化graphic.drawable
6.id轉化成Bitmap
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)
來自: http://blog.csdn.net//caroline_wendy/article/details/42704919
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!