0

我正在尝试拍摄照片并将其显示在图像视图中。

        public class next extends Activity{

         public void onCreate(Bundle savedInstanceState) {
                 super.onCreate(savedInstanceState);
                 setContentView(R.layout.next);         Button cbutton = (Button) findViewById(R.id.capture); /* Capture Photo */
                    cbutton.setOnClickListener(new OnClickListener() {

                public void onClick(View v)         { 
                        Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
                        startActivityForResult(intent,0);       }       });

             }
         @Override  
public void startActivityForResult(Intent intent, int requestCode) {        
ImageView iv
         = (ImageView) findViewById(R.id.imageView1);   
        if(requestCode == 0)        
    {       Bitmap theImage = (Bitmap) data.getExtras().get("data");
            iv.setImageBitmap(theImage);        
}}}

所以这是我用过的代码。现在的问题是我在“数据”下得到了红线

Bitmap theImage = (Bitmap) ***data***.getExtras().get("data");

而且我不知道原因,谁能解释我做错了什么或解决我的问题的任何其他方法?

4

2 回答 2

0

Variable data is neither declared no passed as parameter to your method, therefor it's marked red.

于 2012-08-25T18:43:06.370 回答
0

这段代码的问题是我覆盖了错误的方法:

public void startActivityForResult(Intent intent, int requestCode) {        
ImageView iv
         = (ImageView) findViewById(R.id.imageView1);   
        if(requestCode == 0)        
    {       Bitmap theImage = (Bitmap) data.getExtras().get("data");
            iv.setImageBitmap(theImage);        
}}

因为当结果来自它通过以下方法显示的活动时:

protected void onActivityResult(int requestCode, int resultCode, Intent data) {


        //ImageView iv = (ImageView) findViewById(R.id.imageView1);
        if(requestCode == 1)
        {

        Bitmap theImage = (Bitmap) data.getExtras().get("data");

                iv.setImageBitmap(theImage);
        }

而已 :)

    }
于 2012-08-26T19:46:59.683 回答