简体   繁体   English

如何将图像一个活动发送到另一个活动?

[英]How to send image one activity to another activity?

I am new in android.i want to pass image in one activity to another activity.I tried many time.but my app gonna crash.plz edit my code with necessary changes.我是 android 新手。我想将一个活动中的图像传递给另一个活动。我尝试了很多次。但我的应用程序会崩溃。请编辑我的代码并进行必要的更改。

Sender activity:发件人活动:

camera=(ImageButton)findViewById(R.id.camera);
            gallery=(ImageButton)findViewById(R.id.gallery);
      camera.setOnClickListener(new View.OnClickListener() {

          @Override
          public void onClick(View view) {
              Intent i =new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
              startActivityForResult(i, 50);
          }
      });

    gallery.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent pickPhoto = new Intent(Intent.ACTION_PICK,
                    android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
            startActivityForResult(pickPhoto , 40);
        }
    });
}

Receiver activity:接收器活动:

package com.androidlink.navigation_bottom;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.support.v7.app.AppCompatActivity;


import android.os.Bundle;
import android.widget.ImageView;
public class Image_set_Activity extends AppCompatActivity 
{


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_image_set_);
    ImageView IV = (ImageView) findViewById(R.id.simpleImageView);

  }
}

Try to override onActivityResult().尝试覆盖 onActivityResult()。 For further reading - https://developer.android.com/training/basics/intents/result进一步阅读 - https://developer.android.com/training/basics/intents/result

Try this code For sending the image试试这个代码 用于发送图像

ImageView imageview = (ImageView) findViewById(R.id.Tab);
BitmapDrawable drawable = (BitmapDrawable) imageView.getDrawable();
Bitmap bitmap = drawable.getBitmap();
final byte[] arr = bitmap.getNinePatchChunk();

imageView.setOnClickListener(View v)
{
Intent intent = new Intent (MainActivity.this,bbb.class);
Intent.putExtra(“image”,arr);
startActivity(intent);
}

For getting the image为了获取图像

Intent I = getIntent();
byte[] arr1 = i.getByteArrayExtra(“image”);
Bitmap map = BitmapFactory.decodeByteArray(arr,0,arr.length);
imageView.setImageBitmap(map);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将图像从一个活动发送到另一个活动 - How to send image from one activity to another 如何将 Jpg 图像从一个活动发送到 android 中的另一个活动? - How to Send Jpg Image from one activity to another activity in android? 如何将一个活动的图像传递到另一活动? - How to pass image one activity to another activity? 如何将图像从一项活动发送到从画廊拍摄的另一项活动? - how to send image from one activity to another taken from gallery? 如何在Kitkat Android中将图像从一个活动发送到另一个活动? - How to send image from one activity to another in kitkat android? 如何在Android中将图像从一个活动发送到另一个活动 - How to send image from one activity to another in android 如何在Android中将图片从一个活动发送到另一个活动? - How to send image from one activity to another in android? 从一个活动向另一个活动发送图像 - send image from one activity to another with intent 将图像从一项活动发送到另一项活动 - send image from one activity to another 如何将来自一个活动的图像 Uri 和来自另一个活动的数据发送到 gettersetter 类中的 firebase - how to send image Uri from One activity and data from another activity into firebase in gettersetter class
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM