android之bitmap和byte[]互轉

//drawable轉bitmap
Bitmap imageBitmap = BitmapFactory.decodeResource(myContext.getResources(), R.drawable.example);

//bitmap轉byte[]
ByteArrayOutputStream byteOutStream = new ByteArrayOutputStream();
imageBitmap.compress(Bitmap.CompressFormat.JPEG, 100, byteOutStream);
byte[] imageBytes = byteOutStream.toByteArray();

//byte[]轉bitmap
if(imageBytes!=null)
     imageBitmap = BitmapFactory.decodeByteArray(imageBytes, 0, imageBytes.length);

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章