![](/img/trans.png)
[英]Android how can I pick image from camera or gallery at the same time with one Intent
[英]How to Pass camera image from one intent to other intent in android?
我正在尝试将相机图像从一种意图发送到另一种意图进行显示。 目前,我正在尝试使用以下方法,
捕获图像后
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch(requestCode)
{
case CAMERA_RECEIPTREQUEST:
if(resultCode== Activity.RESULT_OK)
{
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 8;
//ImageView jpgView = (ImageView)findViewById(R.id.imageView1);
Bitmap receipt = BitmapFactory.decodeFile(photo.toString(),options);
Intent imagepass = new Intent(Activity1.this,Activity2.class);
imagepass.putExtra("imagepass", imagepass);
startActivity(imagepass);
在第二活动中
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.receiptreview);
//creating view ids
createViewIds();
Bitmap receiptimage = (Bitmap) getIntent().getExtras().getParcelable("imagepass");
receipt.setImageBitmap(receiptimage);
}
但它显示StackOverFlow错误,
at java.util.HashMap$EntrySet.iterator(HashMap.java:944)
at android.os.Parcel.writeMapInternal(Parcel.java:486)
at android.os.Bundle.writeToParcel(Bundle.java:1552)
at android.os.Parcel.writeBundle(Parcel.java:502)
at android.content.Intent.writeToParcel(Intent.java:5477)
我不确定我是否尝试使用错误的方法。我正在寻找一些示例或解决方案。
感谢您的帮助。
采用
Bitmap receipt = BitmapFactory.decodeFile(photo.toString(),options);
Intent imagepass = new Intent(Activity1.this,Activity2.class);
imagepass.putExtra("imagepass", receipt );
startActivity(imagepass);
代替
Bitmap receipt = BitmapFactory.decodeFile(photo.toString(),options);
Intent imagepass = new Intent(Activity1.this,Activity2.class);
imagepass.putExtra("imagepass", imagepass);
startActivity(imagepass);
您要在imagepass.putExtra("imagepass", imagepass);
中传递Intent实例imagepass imagepass.putExtra("imagepass", imagepass);
因此,在imagepass.putExtra("imagepass", receipt );
传递Bitmap
实例imagepass.putExtra("imagepass", receipt );
编辑:
要在android中的活动之间传递图像(位图),请参阅以下文章:
从我可以看到您传递了要发送的意图。 尝试:
imagepass.putExtra("imagepass", receipt);
可能会工作,对我自己来说仍然是新手。
我们可以尝试另一种将图像转换为字节数组,然后通过intent传递字节数组的方法,在调用活动时,我们可以将字节数组转换为位图
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.