[英]I want to Passing a image from Drawable from one activity to Another via Intent?
I am using this part of code to send the image... 我正在使用这部分代码发送图像...
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);
And to get the image i am using this sort of code... 为了获得图像,我正在使用这种代码......
imag_link = getIntent().getStringExtra("valueq");
Toast.makeText(getApplicationContext(), imag_link, Toast.LENGTH_LONG)
.show();
Its Toast is providing a blank toast.... 它的吐司提供一个空白的吐司....
I want to set the image to a certain imageview....Suggestion please 我想将图像设置为某个图像视图....建议请
you can pass byte array and get bytearray and then make bitmap 你可以传递字节数组并获取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);
In Activity B you receive intent with byte array (decoded picture) and apply it as source to ImageView: 在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);
You are passing an int value in intent. 您正在传递意图中的int值。 so call
所以打电话
imag_link = getIntent().getIntExtra("valueq", value);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.