1 //take the image to byte[] 2 byte[] byteIcon = userIcon; 3 4 //將字節數組即頭像從二進制流轉換成drawable 5 if(byteIcon != null){ 6 7 ByteArrayInputStream bais = new ByteArrayInputStream(byteIcon); 8 9 userIconDrawable = Drawable.createFromStream(bais, "image"); 10 11 } 12 13 14 15 16 17 BitMap userIcon; 18 19 20 //將bitmap轉換成drawable 21 ByteArrayOutputStream os = new ByteArrayOutputStream(); 22 //參數1轉換類型,參數2壓縮質量,參數3字節流資源
userIcon.compress(CompressFormat.PNG, 100, os);
1 //將Drawable 轉成bitmap 2 BitmapDrawable tempDrawable = (BitmapDrawable) DrawableImage; 3 tempDrawable.getBitmap();