android camera的简单demo

package com.example.camera;

import android.os.Bundle;
import android.widget.ImageView;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;


public class MainActivity extends Activity {

    private final static int CAMERA_RESULT =0;
    private ImageView view;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        view=(ImageView)findViewById(R.id.imageview);
        Intent i=new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);//启动intent
        startActivityForResult(i, CAMERA_RESULT);
    }
    //返回接收
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        // TODO Auto-generated method stub
        super.onActivityResult(requestCode, resultCode, data);
        if(resultCode==RESULT_OK){
            Bundle bundle=data.getExtras();
            Bitmap bitmap=(Bitmap) bundle.get("data");
            view.setImageBitmap(bitmap);
        }
    }

  

}
posted @ 2012-10-04 10:50  春天的故事  阅读(2167)  评论(0编辑  收藏  举报