[英]How to Pass camera image from one intent to other intent in android?
I am trying to send camera image from one intent to another intent to display. 我正在尝试将相机图像从一种意图发送到另一种意图进行显示。 Currently i am trying using the following method,
目前,我正在尝试使用以下方法,
Once the image captured 捕获图像后
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);
In second activity 在第二活动中
@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);
}
But it shows StackOverFlow error, 但它显示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)
I am not sure whether i am trying wrong method.I am looking for some sample or solution to this. 我不确定我是否尝试使用错误的方法。我正在寻找一些示例或解决方案。
Thank for your help guys. 感谢您的帮助。
use 采用
Bitmap receipt = BitmapFactory.decodeFile(photo.toString(),options);
Intent imagepass = new Intent(Activity1.this,Activity2.class);
imagepass.putExtra("imagepass", receipt );
startActivity(imagepass);
instead of 代替
Bitmap receipt = BitmapFactory.decodeFile(photo.toString(),options);
Intent imagepass = new Intent(Activity1.this,Activity2.class);
imagepass.putExtra("imagepass", imagepass);
startActivity(imagepass);
You are passing Intent instance imagepass in imagepass.putExtra("imagepass", imagepass);
您要在
imagepass.putExtra("imagepass", imagepass);
中传递Intent实例imagepass imagepass.putExtra("imagepass", imagepass);
so pass Bitmap
instance in imagepass.putExtra("imagepass", receipt );
因此,在
imagepass.putExtra("imagepass", receipt );
传递Bitmap
实例imagepass.putExtra("imagepass", receipt );
EDIT: 编辑:
for passing images (bitmaps) between activities in android see these posts: 要在android中的活动之间传递图像(位图),请参阅以下文章:
how do you pass images (bitmaps) between android activities using bundles? 如何使用捆绑包在android活动之间传递图像(位图)?
How can I pass a Bitmap object from one activity to another 如何将位图对象从一个活动传递到另一个活动
From what I can see your passing the intent itself to be send. 从我可以看到您传递了要发送的意图。 Try:
尝试:
imagepass.putExtra("imagepass", receipt);
Might work, still new to android myself. 可能会工作,对我自己来说仍然是新手。
我们可以尝试另一种将图像转换为字节数组,然后通过intent传递字节数组的方法,在调用活动时,我们可以将字节数组转换为位图
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.