首页 新闻 赞助 找找看

android参数传递出错

0
悬赏园豆:30 [已关闭问题] 关闭于 2012-05-27 21:42

最近写了一段代码,两个Activity,第一个Activity向第二个Activity传一张图片的位置信息(第二个Activity要用第一张图片的信息),第二个Activity部分内容为

class Image{
    public Bitmap image;
    public int imlen=0;//图像总像素数
    public int width;//图像像素矩阵宽
    public int height;//图像像素高
    public int[] pixel;
}
public class second extends Activity{
    /** Called when the activity is first created. */
    private ImageButton btn1;//打开文件
    private EditText edt3;//显示第二幅图片位置
    private ImageButton btn3;//Embedded
    public ImageButton btn4;//extract
    private ImageButton btn5;//save
    private EditText edt;//password
    private EditText edt1;//message
    private ImageView img1;
    public ProgressBar bar;
    public Random random = new Random();
    public String key = null;
    static int[] epixel= null;
    public int p=0;//进度条提示
    //static int b=0;
    public Image spic = new Image();
    public Image fpic = new Image();//也许错
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Intent intent = getIntent();
        findview();
        btn1.setOnClickListener(new MyButtonListener());//打开文件,寻找图片
        setImg();
        String location = intent.getStringExtra("location");
        BitmapFactory.Options options = new BitmapFactory.Options();  
        if(options != null && location != null)
        {
            Toast.makeText(second.this,"有执行噢", Toast.LENGTH_SHORT).show();
        options.inSampleSize = 2;  
        fpic.image = BitmapFactory.decodeFile(location, options);//get first image
        if(fpic.image != null)
        {
            Toast.makeText(second.this,"也有执行噢", Toast.LENGTH_SHORT).show();
            fpic.image = fpic.image.copy(Bitmap.Config.ARGB_8888, true);
            fpic.imlen = (int) fpic.image.getHeight()*fpic.image.getWidth();
            fpic.pixel = new int[fpic.imlen];
            fpic.image.getPixels(fpic.pixel,0,fpic.image.getWidth(),0,0,fpic.image.getWidth(),fpic.image.getHeight());
            fpic.height = fpic.image.getHeight();
            fpic.width = fpic.image.getWidth();
        }
        }//第一幅图片读取完
        btn3.setOnClickListener(new OnClickListener(){
            @Override
            public void onClick(View v) {//TODO Auto-generated method stub
                //if(b==0)
                    //Toast.makeText(second.this,"请先从图库中选择图片", Toast.LENGTH_SHORT).show();
                //else
                    if(edt.getText().toString().length()==0)
                       Toast.makeText(second.this,"请先输入要密钥", Toast.LENGTH_SHORT).show();
                    else
                if(edt1.getText().toString().length()==0)
                       Toast.makeText(second.this,"请先输入要嵌入的内容", Toast.LENGTH_SHORT).show();
                else{
                       try {
                           Toast.makeText(second.this,"开始啦", Toast.LENGTH_SHORT).show();
                           key = edt.getText().toString();
                           byte[] message = edt1.getText().toString().getBytes("ASCII");//嵌入信息(Byte形式)
                           int[] embed = new int[message.length*8];
                           embed= match(message,fpic.pixel);//得到匹配序列
                           String slocation = edt3.getText().toString();
                           int c= 9;
                           BitmapFactory.Options options = new BitmapFactory.Options();  
                            if(options != null && slocation != null)
                            {
                                options.inSampleSize = 2;  
                                spic.image = BitmapFactory.decodeFile(slocation, options);//get first image
                                if(spic.image != null)
                                {
                                    spic.image = spic.image.copy(Bitmap.Config.ARGB_8888, true);
                                    spic.imlen = (int) spic.image.getHeight()*spic.image.getWidth();
                                    spic.pixel = new int[spic.imlen];
                                    spic.image.getPixels(spic.pixel,0,spic.image.getWidth(),0,0,spic.image.getWidth(),spic.image.getHeight());
                                }
                                }
                            spic.height = spic.image.getHeight();
                            spic.pixel = embeded(spic.pixel,embed,key);//嵌入匹配序列
                            edt.setText("");//将Password置空
                            edt1.setText("");//将嵌入信息置空
                            //b=2;
                       }
                       catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                        Toast.makeText(second.this,"异常抛出啦!!!!问题没有解决,加油吧", Toast.LENGTH_SHORT).show();
                    } 
                   }
            }
});
       //btn3.setOnClickListener(new EmButtonListener());
}
    public void setImg() {
        // TODO Auto-generated method stub
        Bundle bun=this.getIntent().getExtras();
        if(bun!=null){
            String str;
            str =bun.getString("FName"); 
            edt3.setText(str);
            Bitmap map=BitmapFactory.decodeFile(bun.getString("FName"));
            img1.setImageBitmap(map);
        }
    }
    public void findview(){
        btn1 = (ImageButton) findViewById(R.id.btn1);
        edt3 = (EditText) findViewById(R.id.edt3);
        btn3 = (ImageButton) findViewById(R.id.btn3);
        btn4 = (ImageButton) findViewById(R.id.btn4);
        btn5 = (ImageButton) findViewById(R.id.btn5);
        edt = (EditText) findViewById(R.id.edt0);
        edt1 =(EditText) findViewById(R.id.edt1);
        img1 = (ImageView) findViewById(R.id.img1);
        bar = (ProgressBar)findViewById(R.id.firstBar);
    }
class MyButtonListener implements OnClickListener {       
        @Override
        public void onClick (View v)
        {
            //TODO Auto-generated method stub
            Intent in=new Intent();
            in.setClass(second.this, FileMang.class);
            startActivity(in);
           // b=1;//定义点击顺序的变量
            finish();
        }
    }其中btn3.setOnClickListener要用到fpic这个类中的pixel数组内容,但是我现在写的代码无法把这个参数传递过来,请教大神们帮助看看,该怎么改

其中btn3.setOnClickListener要用到fpic这个类中的pixel数组内容,但是我现在写的代码无法把这个参数传递过来,请教大神们帮助看看,该怎么改

liuyufeng的主页 liuyufeng | 初学一级 | 园豆:44
提问于:2012-05-25 20:39
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册