android相机预览

时间:2012-04-06 19:51:04

标签: android camera

我从youtube在Android中的相机获得了这个教程,但它不在我的应用程序上,我似乎无法找到错误。它给出了一个运行时错误“进程(”“)意外停止了。

public class Camera extends Activity {
ImageView iv;

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.photo);

    iv= (ImageView) findViewById(R.id.imageView1);

    Button btn =(Button) findViewById(R.layout.photo);
    btn.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            // TODO Auto-generated method stub
            Intent intent =new Intent (android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
            startActivityForResult(intent, 0);

        }
    });
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    {
        if(requestCode ==0)
        {
            Bitmap theImage =(Bitmap)data.getExtras().get("data");
        iv.setImageBitmap(theImage);
        }
}

}}

0 个答案:

没有答案