我在意图的帮助下发送图像如下
Uri profileImage = Uri.parse("android.resource://Tset/res/drawable-hdpi/arr.jpeg");
details.setType("image/png");
details.putExtra(Intent.EXTRA_STREAM, profileImage);
startActivity(details);
如何在接收端活动中获取图像路径?
答案 0 :(得分:3)
试试这个 使用意图
从当前活动传递图像网址Intent myIntent = new Intent(this, MyImageViewActivity.class);
Bundle bundle = new Bundle();
bundle.putString("image", path);
myIntent.putExtras(bundle);
startActivityForResult(myIntent, 0);
这里的路径是
String path="android.resource://Tset/res/drawable-hdpi/arr.jpeg"
在您的接收活动中
Bundle bundle = this.getIntent().getExtras();
String path = bundle.getString("image");
答案 1 :(得分:2)
最后我在图片的id的帮助下完成了如下操作! ! 谢谢你的回复! !
profilePictureID=R.drawable.image name;//name of image in drawable folder dont use extensions like.jpg and all
IntentObject.putExtra("ImageID",profilePictureID);
startActivity(IntenetObject);
接收活动
int pictureId=getIntent().getIntExtra("ImageID",0);
profilePicture.setImageResource(pictureId);
答案 2 :(得分:1)
在您的通话活动中......
Intent i = new Intent(this, NextActivity.class);
Bitmap b; // your bitmap
ByteArrayOutputStream bs = new ByteArrayOutputStream();
b.compress(Bitmap.CompressFormat.PNG, 50, bs);
i.putExtra("byteArray", bs.toByteArray());
startActivity(i);
...并在您的接收活动中
if(getIntent().hasExtra("byteArray")) {
ImageView previewThumbnail = new ImageView(this);
Bitmap b = BitmapFactory.decodeByteArray(
getIntent().getByteArrayExtra("byteArray"),0,getIntent().getByteArrayExtra("byteArray").length);
previewThumbnail.setImageBitmap(b);
}
File imgFile = new File(“/sdcard/Images/test_image.jpg”);
if(imgFile.exists())
Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
答案 3 :(得分:1)
试试这个..
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(new File(path)), "image/png");
startActivity(intent);
答案 4 :(得分:1)
您可以转换为bytearray并传递相同的内容。在下一个活动中解码并显示相同内容。
使用意图传递图像
Intent i = new Intent(this, NextActivity.class);
Bitmap b; // your bitmap
ByteArrayOutputStream bs = new ByteArrayOutputStream();
b.compress(Bitmap.CompressFormat.PNG, 50, bs);
i.putExtra("byteArray", bs.toByteArray());
startActivity(i);
接收
if(getIntent().hasExtra("byteArray")) {
ImageView previewThumbnail = new ImageView(this);
Bitmap b = BitmapFactory.decodeByteArray(
getIntent().getByteArrayExtra("byteArray"),0,getIntent().getByteArrayExtra("byteArray").length);
previewThumbnail.setImageBitmap(b);
}
如果您要传递字符串网址
How do you pass a string from one activity to another?
编辑:
通过uri
Uri uri = Uri.parse("android.resource://com.example.passurl/drawable/ic_launcher");
// com.example.passurl is the package name
// ic_launcher is the image name
Intent i = new Intent(MainActivity.this,NewActivity.class);
i.setData(uri);
startActivity(i);
接收
ImageView iv= (ImageView) findViewById(R.id.imageView1); // initialize image view
if(getIntent().getData()!=null)
{
Uri path = getIntent().getData();
iv.setImageURI(path); //set the image
}