使用android意图在活动中传递android位图数据我有一个位图变量bmp在Activity1中,我想将位图发送到Activity2下面是我用来传递它的意图的代码。Intent in1 = new Intent(this, Activity2.class);in1.putExtra("image",bmp);startActivity(in1);在Activity 2中,我尝试使用以下代码访问位图Bundle ex = getIntent().getExtras();Bitmap bmp2 = ex.getParceable("image");ImageView result = (ImageView)findViewById(R.Id.imageView1);result.setImageBitmap(bmp);应用程序毫无例外地运行,但它没有给出预期的结果。
3 回答
慕容森
TA贡献1853条经验 获得超18个赞
//Convert to byte arrayByteArrayOutputStream stream = new ByteArrayOutputStream();bmp.compress(Bitmap.CompressFormat.PNG, 100, stream);byte[] byteArray = stream.toByteArray();Intent in1 = new Intent(this, Activity2.class);in1.putExtra("image",byteArray);
byte[] byteArray = getIntent().getByteArrayExtra("image");Bitmap bmp = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);
编辑
try { //Write file String filename = "bitmap.png"; FileOutputStream stream = this.openFileOutput(filename, Context.MODE_PRIVATE); bmp.compress(Bitmap.CompressFormat.PNG, 100, stream); //Cleanup stream.close(); bmp.recycle(); //Pop intent Intent in1 = new Intent(this, Activity2.class); in1.putExtra("image", filename); startActivity(in1);} catch (Exception e) { e.printStackTrace();}
Bitmap bmp = null;String filename = getIntent().getStringExtra("image");try { FileInputStream is = this.openFileInput(filename); bmp = BitmapFactory.decodeStream(is); is.close();} catch (Exception e) { e.printStackTrace();}
冉冉说
TA贡献1877条经验 获得超1个赞
精慕HU
TA贡献1845条经验 获得超8个赞
intent.putExtra("uri", Uri);
Bitmap bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(),Uri.parse(uri));
- 3 回答
- 0 关注
- 421 浏览
添加回答
举报
0/150
提交
取消