如何通过意图传递的图像? [英] how to pass images through intent?

查看:136
本文介绍了如何通过意图传递的图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

头等舱

public class ChooseDriver extends Activity implements OnItemClickListener {

  private static final String rssFeed   = "http://trade2rise.com/project/seattle/windex.php?itfpage=driver_list";  
  private static final String ARRAY_NAME = "itfdata";
  private static final String ID = "id";
  private static final String NAME = "name";
  private static final String IMAGE = "image";

  List<Item> arrayOfList;
  ListView listView;
  MyAdapter objAdapter1;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.choose_driver);

    listView = (ListView) findViewById(R.id.listView1);
    listView.setOnItemClickListener(new OnItemClickListener() {
      @Override
      public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
        Item item = (Item) objAdapter1.getItem(position);
        Intent intent = new Intent(ChooseDriver.this, DriverDetail.class);
        intent.putExtra(ID, item.getId());
        intent.putExtra(NAME, item.getName().toString());
        // intent.putExtra(IMAGE, item.getImage().toString());        
        // image.buildDrawingCache();
        // Bitmap image= image.getDrawingCache();
        Bundle extras = new Bundle();
        // extras.putParcelable("imagebitmap", image);
        intent.putExtras(extras);

        startActivity(intent); 
      }
    });
  }
}

第二类

public class DriverDetail extends Activity {

  private ImageLoader imageLoader;

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.driver_detail);

    ImageView imageView = (ImageView) findViewById(R.id.imageView1);
    TextView tv = (TextView) findViewById(R.id.tvDname);

    Bundle extras = getIntent().getExtras();
    Bitmap bmp = (Bitmap) extras.getParcelable("imagebitmap");
    imageView.setImageBitmap(bmp );
    //imageView.set(getIntent().getExtras().getString("image"));
    tv.setText(getIntent().getExtras().getString("name"));
  } 
}

通过使用它,我可以显示文字非常好,但我不能显示在第二Aactivity图像。

By using it I can show text very well, but I can't show an image on second Aactivity.

推荐答案

您可以将它作为一个字节数组,并建立了位图显示下一个屏幕上。但使用的意图,我们可以把小的图像,例如缩略图,图标etc.else它会给出绑定失败。

You can pass it as a byte array and build the bitmap for display on the next screen. but using intent we can send small images like thumbnails,icons etc.else it will gives bind failure.

Intent _intent = new Intent(this, newscreen.class);
Bitmap _bitmap; // your bitmap
ByteArrayOutputStream _bs = new ByteArrayOutputStream();
_bitmap.compress(Bitmap.CompressFormat.PNG, 50, _bs);
i.putExtra("byteArray", _bs.toByteArray());
startActivity(i);

接收器的工作

if(getIntent().hasExtra("byteArray")) {
ImageView _imv= new ImageView(this);
Bitmap _bitmap = BitmapFactory.decodeByteArray(
        getIntent().getByteArrayExtra("byteArray"),0,getIntent().getByteArrayExtra("byteArray").length);        
_imv.setImageBitmap(_bitmap);
}

这篇关于如何通过意图传递的图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆