Activity 간 bitmap 전달.
보내는 Activity:
Bitmap -> ByteArray 로 전환 후 Intent의 Extra로 넣어서 전달.
Bitmap bitmap = snapshot; ByteArrayOutputStream stream = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream); byte[] byteArray = stream.toByteArray(); Intent intent = new Intent(Activity.this, AnotherActivity.class); intent.putExtra("image",byteArray); startActivity(intent); |
받는 Activity:
ByteArray -> Bitmap으로 전환.
byte[] arr = getIntent().getByteArrayExtra("image"); Bitmap bm = BitmapFactory.decodeByteArray(arr, 0, arr.length); |
보낼때 :
BitmapDrawable d = (BitmapDrawable)(ImageView)view.findViewById(R.id.imageView1)).getDrawable();
Bitmap b = d.getBitmap();
imgview.setImageBitmap(b);
intent.putExtra("bm", (Bitmap)b);
받는 Activity :
Bitmap bm = (Bitmap)in.getExtras().get("bm");
imgview.setImageBitmap(bm);
또는
Bitmap bm = (Bitmap)in.getParcelableExtra("bm");
imgview.setImageBitmap(bm);
주의
byteArray 사이즈는 40k까지만 전송 가능. 그 이상 크기의 배열을 전송할 경우에는
!!! FAILED BINDER TRANSACTION !!!
오류 뜸.
출저 : http://smile8916.tistory.com/72