Android將圖像轉換成流存儲與將流轉換成圖像


 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();

 

 




 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM