閱讀897 返回首頁    go 技術社區[雲棲]


android位圖在activity之間傳遞的問題

采用傳統的方式,將bitmap轉化為字節數組,利用intent傳遞byte[]。

bitmap專為為byte[]的代碼如下:

 Intent in = new Intent(TestAnimation.this,CameraDemo.class);
Bitmap m = ((BitmapDrawable)(getResources().getDrawable(R.drawable.ic_launcher))).getBitmap();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
m.compress(Bitmap.CompressFormat.JPEG, 100, baos);
byte[] bitmapByte = baos.toByteArray();
in.putExtra("bitmap", bitmapByte);
startActivity(in);`

接收方接收到byte數組可以轉化為bitmap,代碼如下:

Intent in = getIntent();
if(in != null){
byte[] bis = in.getByteArrayExtra("bitmap");
System.out.println("-------CameraDemo bis length="+bis.length);
Bitmap bitmap = BitmapFactory.decodeByteArray(bis, 0, bis.length);

}


最後更新:2017-04-04 07:03:07

  上一篇:go 阿裏雲手機流產的三個原因
  下一篇:go 2013穀歌發展五要點:安卓能否成開發者首選