intent传参 之 Bitmap

来源:互联网 发布:李涛疯狂淘宝培训 编辑:程序博客网 时间:2024/06/10 10:33
要实现一个功能 

单击一个listView 的列表项, 进入详情页面, 跳转的过程中要传递一个 Bitmap   

[java] view plaincopy
  1. // ListView的单击事件  
  2. @Override  
  3. protected void onListItemClick(ListView l, View v, int position, long id) {  
  4. super.onListItemClick(l, v, position, id);  
  5. //产品图像  
  6. ImageView imageView = ((ImageView)layout.findViewById(R.id.product_img));  
  7. //Bitmap productImg = imageView.getDrawingCache();//??? 返回null  
  8. BitmapDrawable mDrawable =  (BitmapDrawable) imageView.getDrawable();  
  9. Bitmap productImg = mDrawable.getBitmap();  
  10. //传递  
  11. Bitmapintent.putExtra("productImg", productImg);  

注意1 productImg = imageView.getDrawingCache();//??? 返回null   

正确的取法是:

BitmapDrawable mDrawable =  (BitmapDrawable) imageView.getDrawable();
 Bitmap productImg = mDrawable.getBitmap();

 

[java] view plaincopy
  1. 接收 :productImg = (Bitmap) bundle.get("productImg");  

0 0
原创粉丝点击