如何从一个活动传递图像数据到另一个活动? [英] How to pass image data from one activity to another activity?

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

问题描述

我用两个活动。一项活动通过点击一个特定的图像显示在 GridView的图片的GridView 它应该显示全屏图像在另一项活动。

我怎样才能做到这一点?

我MyGridView.java

  mGridView.setOnItemClickListener(新OnItemClickListener(){
@覆盖
公共无效onItemClick(适配器视图<>母公司,视图V,INT位置,长的id){
    // TODO自动生成方法存根
    Toast.makeText(getApplicationContext(),图像+(位置+ 1),Toast.LENGTH_SHORT).show();
    的System.out.println(ID);
    意图I =新的意图(这一点,MyImageViewActivity.class);
    束束=新包();
    bundle.putInt(形象,位置);
    i.putExtras(包);
    startActivityForResult(ⅰ,0);
}
});
 

解决方案

在MyGridView:(someInteger是一个整数,再presents所选图像的指数

 意图myIntent =新的意图(这一点,MyImageViewActivity.class);
束束=新包();
bundle.putInt(形象,someInteger);
myIntent.putExtras(包);
startActivityForResult(myIntent,0);
 

在MyImageViewActivity:

 捆绑包= this.getIntent()getExtras()。
INT PIC = bundle.getInt(图像);
 

当然,你可以在包中放任何东西!也许一个字节数组或东西

I am using two activities. One activity displays images in a GridView and by clicking on a particular image in that GridView it should display the full screen image in another activity.

How can I achieve this?

My MyGridView.java

mGridView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View v, int position,long id) {
    // TODO Auto-generated method stub
    Toast.makeText(getApplicationContext(), "Image"+(position+1),Toast.LENGTH_SHORT).show();
    System.out.println(id);
    Intent i = new Intent(this, MyImageViewActivity.class);
    Bundle bundle = new Bundle();
    bundle.putInt("image", position);
    i.putExtras(bundle);
    startActivityForResult(i, 0);
}
});

解决方案

In MyGridView: (someInteger is an integer that represents the index of the selected image

Intent myIntent = new Intent(this, MyImageViewActivity.class);
Bundle bundle = new Bundle();
bundle.putInt("image", someInteger);
myIntent.putExtras(bundle);
startActivityForResult(myIntent, 0);

In MyImageViewActivity:

Bundle bundle = this.getIntent().getExtras();
int pic = bundle.getInt("image");

of course, you can put anything in the bundle! maybe a byte array or something

这篇关于如何从一个活动传递图像数据到另一个活动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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