我有一个带有图片ID的imageview,我想在点击它以在新活动中显示它但它会抛出 var blockArray = [];
function Block () {
blockArray.push(this.Block);
}
。该图像在我的drawables文件夹中,我尝试了Open Image in full screen android的答案,但它没有用。
ActivityNotFoundException
答案 0 :(得分:0)
您可以使用它来解决:
Uri uri = Uri.parse("android.resource://com.example.deepanshu.tourguideapp/drawable_hdpi/voukatio");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
//context.startActivity(intent); maybe you have to use this, insted of startActivity(intent);
}else {
Toast.makeText(this,"No app found.",Toast.LENGTH_SHORT).show();
}
答案 1 :(得分:0)
假设我们有ActifityA& ActivityB 在First Activity(ActivityA)中,我们可以使用putExtra解码我们的图像并通过intent发送它:
Bitmap imageBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_image_name);
ByteArrayOutputStream byteArrayOutStream = new ByteArrayOutputStream();
imageBitmap.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutStream);
byte[] b = byteArrayOutStream.toByteArray();
Intent intent = new Intent(this, ActivityB.class);
intent.putExtra("myImage", b);
startActivity(intent);
在ActivityB中,我们可以接收带有字节数组的意图,并直接作为位图应用于ImageView:
Bundle extras = getIntent().getExtras();
byte[] b = extras.getByteArray("myImage");
Bitmap bitmap = BitmapFactory.decodeByteArray(b, 0, b.length);
ImageView imageView = (ImageView) findViewById(R.id.myImageView);
imageView.setImageBitmap(bitmap);
希望这会有所帮助。