如何实现调用手机的拍照功能并返回所拍摄的照片

分享到:
import android.app.Activity; 
import android.content.Intent; 
import android.graphics.Bitmap; 
import android.os.Bundle; 
import android.provider.MediaStore; 
import android.util.Log; 

public class PhotographActivity extends Activity { 
    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
        super.onCreate(savedInstanceState); 
        setContentView(R.layout.main); 
        try { 
             Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); 
             startActivityForResult(intent, 0); 
        } catch (Exception e) { 
            System.out.println(e.getMessage());
        } 
    }

    protected void onActivityResult(int requestCode, int resultCode, Intent data) 
    { 
        try { 
            if (requestCode != 0) { 
                return; 
            } 
            super.onActivityResult(requestCode, resultCode, data); 
            Bundle extras = data.getExtras(); 
            Bitmap b = (Bitmap) extras.get("data"); 
            /*
               得到图片对图片处理...
            */ 
            
              
        } catch (Exception e) { 
            // TODO: handle exception 
            System.out.println(e.getMessage()); 
        } 
    } 

}

昵    称:
验证码:

相关文档: