如何將Bitmap對象從一個活動傳遞到另一個活動在我的活動中,我創建了一個Bitmap對象,然后我需要啟動另一個Activity,我怎么通過這個?Bitmap對象來自子活動(即將啟動的子活動)?
3 回答

長風秋雁
TA貢獻1757條經驗 獲得超7個贊
Bitmap
Parcelable
Intent intent = new Intent(this, NewActivity.class);intent.putExtra("BitmapImage", bitmap);
Intent intent = getIntent(); Bitmap bitmap = (Bitmap) intent.getParcelableExtra("BitmapImage");

元芳怎么了
TA貢獻1798條經驗 獲得超7個贊
public String createImageFromBitmap(Bitmap bitmap) { String fileName = "myImage";//no .png or .jpg needed try { ByteArrayOutputStream bytes = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.JPEG, 100, bytes); FileOutputStream fo = openFileOutput(fileName, Context.MODE_PRIVATE); fo.write(bytes.toByteArray()); // remember close file output fo.close(); } catch (Exception e) { e.printStackTrace(); fileName = null; } return fileName;}
//here context can be anything like getActivity() for fragment, this or MainActivity.this Bitmap bitmap = BitmapFactory.decodeStream(context.openFileInput("myImage"));
注
添加回答
舉報
0/150
提交
取消