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

 

你可能感兴趣的:(android之界面,android,开发笔记)