Android 我想通过Intent将图像从一个活动传递到另一个活动?

Android 我想通过Intent将图像从一个活动传递到另一个活动?,android,Android,我正在使用这部分代码发送图像 public void onClick(View v) { Intent goto_membersdealsdetails = new Intent( "com.abc.cd.FE"); goto_membersdealsdetails.putExtra("valueq", R.drawable.app_icon);

我正在使用这部分代码发送图像

public void onClick(View v) {

                Intent goto_membersdealsdetails = new Intent(
                        "com.abc.cd.FE");

                goto_membersdealsdetails.putExtra("valueq", R.drawable.app_icon);


                v.getContext().startActivity(goto_membersdealsdetails);
为了得到图像,我使用了这种代码

   imag_link = getIntent().getStringExtra("valueq");

   Toast.makeText(getApplicationContext(), imag_link, Toast.LENGTH_LONG)
                    .show();
它的吐司是提供一个空白吐司


我想将图像设置为特定的图像视图…建议您可以传递字节数组并获取字节数组,然后制作位图

 Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);     
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos); 
    byte[] b = baos.toByteArray();

    Intent intent = new Intent(this, ActivityB.class);
    intent.putExtra("picture", b);
    startActivity(intent);
在活动B中,您通过字节数组(解码图片)接收意图,并将其作为源应用于ImageView:

Bundle extras = getIntent().getExtras();
byte[] b = extras.getByteArray("picture");

Bitmap bmp = BitmapFactory.decodeByteArray(b, 0, b.length);
ImageView image = (ImageView) findViewById(R.id.imageView1);
image.setImageBitmap(bmp);

您可以传递字节数组并获取字节数组,然后生成位图

 Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);     
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos); 
    byte[] b = baos.toByteArray();

    Intent intent = new Intent(this, ActivityB.class);
    intent.putExtra("picture", b);
    startActivity(intent);
在活动B中,您通过字节数组(解码图片)接收意图,并将其作为源应用于ImageView:

Bundle extras = getIntent().getExtras();
byte[] b = extras.getByteArray("picture");

Bitmap bmp = BitmapFactory.decodeByteArray(b, 0, b.length);
ImageView image = (ImageView) findViewById(R.id.imageView1);
image.setImageBitmap(bmp);

您正在传递一个int值。叫

imag_link = getIntent().getIntExtra("valueq", value);

您正在传递一个int值。叫

imag_link = getIntent().getIntExtra("valueq", value);

这起作用了:int imag_link=getIntent().getIntExtra(“valueq”,R.drawable.bar_normal);Toast.makeText(getApplicationContext(),imag_链接,Toast.LENGTH_LONG.show();这起作用了:int imag_link=getIntent().getIntExtra(“valueq”,R.drawable.bar_normal);Toast.makeText(getApplicationContext(),imag_链接,Toast.LENGTH_LONG.show();