获取 ImageView 的图像并将其发送到具有 Intent 的活动 [英] get ImageView's image and send it to an activity with Intent
本文介绍了获取 ImageView 的图像并将其发送到具有 Intent 的活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的应用中有许多产品的网格.当用户选择网格中的项目之一时,我将启动一个新活动作为 DIALOG 框并显示项目的名称、数量和图像.但是我无法动态发送图像源.
I have a grid of many products in my app. when the user selects one of the item in the grid, I am starting a new activity as DIALOG box and display the item's name,quantity and image. But I cannot send the image source dynamically.
这是我的代码
gridView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v,int position, long id) {
//Toast.makeText(getApplicationContext(),((TextView) v.findViewById(R.id.grid_item_label)).getText(), Toast.LENGTH_SHORT).show();
Intent item_intent = new Intent(MainActivity.this, Item.class);
item_intent.putExtra("name",((TextView) v.findViewById(R.id.grid_item_label)).getText());
item_intent.putExtra("quantity",((TextView) v.findViewById(R.id.grid_item_quantity)).getText());
//my problem is here***************************************************
ImageView my_image = findViewById(R.id.grid_item_image).getDrawable();
item_intent.putExtra("image",my_image.getXXXXX());
//*********************************************************************
MainActivity.this.startActivity(item_intent);
}
});
我应该使用什么来从 ImageView 获取图像源?
What should I use to get the image source from ImageView?
推荐答案
Use Bundle like
Use Bundle like
imageView.buildDrawingCache();
Bitmap image= imageView.getDrawingCache();
Bundle extras = new Bundle();
extras.putParcelable("imagebitmap", image);
intent.putExtras(extras);
startActivity(intent);
Bundle extras = getIntent().getExtras();
Bitmap bmp = (Bitmap) extras.getParcelable("imagebitmap");
image.setImageBitmap(bmp );
这篇关于获取 ImageView 的图像并将其发送到具有 Intent 的活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文