![](/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.