繁体   English   中英

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

[英]I want to Passing a image from Drawable from one activity to Another via Intent?

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

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();

它的吐司提供一个空白的吐司....

我想将图像设置为某个图像视图....建议请

你可以传递字节数组并获取bytearray然后制作位图

 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);

在Activity 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);

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM