2012-09-17 51 views
3

通过点击一个按钮,我是从画廊拾取图像和设定它到ImageView的......这里是代码..获取位图图像,并把它转换成位图变量

protected void onActivityResult(int requestCode, int resultCode, Intent data) 
    { 
     super.onActivityResult(requestCode, resultCode, data); 
     if(requestCode==RESULT_LOAD_IMAGE && resultCode == RESULT_OK && null != data) 
     { 
       Uri selectedImage = data.getData(); 
       String[] filePathColumn = { MediaStore.Images.Media.DATA }; 

       Cursor cursor = getContentResolver().query(selectedImage, 
         filePathColumn, null, null, null); 
       cursor.moveToFirst(); 

       int columnIndex = cursor.getColumnIndex(filePathColumn[0]); 
       String picturePath = cursor.getString(columnIndex); 
       cursor.close(); 

       ImageView imageView = (ImageView) findViewById(R.id.iImage); 
       imageView.setImageBitmap(BitmapFactory.decodeFile(picturePath)); 

     } 
    } 

现在我想要在位图变量中获得这个图像,并需要将它添加到ArrayList作为位图变量...任何人都可以帮助我?

回答

2

你可以只使用一个变量为位图,如:

Bitmap imagetopass; 
imagetopass=BitmapFactory.decodeFile(picturePath); 

刚过:

imageView.setImageBitmap(BitmapFactory.decodeFile(picturePath)); 

然后你就可以使用这个变量imagetopass。