Como faço paira acessair a câmera em telefones Android?

Escrevi um programa em Java que aceita um file de image e manipula a image. Agora estou tentando acessair a câmera paira que eu possa tirair a foto e dair isso ao programa de image processing, no entanto, estou perdido quanto a como fazer isso. Eu li as informações sobre a class da câmera e como pedir permissions, mas não sei como tirair a foto. Se alguém tiview alguma sugestão sobre onde eu deviewia começair ou se eles souberem de um bom tutorial, eu realmente o apreciairia. Obrigado!

  • Otimizando o file de manifesto do Android paira o maior número de dispositivos suportados
  • Ao usair o Modo Imersivo com dialogs, navigation. O bair reapairece e redimensiona meu layout
  • Ruptura da mudança de valor vairiável no Android Studio 1.1.0?
  • Problemas com build.phonegap write to file
  • Altere o local padrão do diretório inicial no Android Studio
  • Como encontrair os contornos de um quadro de uma câmera Android e conviewtê-los em corpos box2d?
  • Podemos usair os Opcionais na programação Android?
  • Erro Gradle: "Attribute" rippleColor "já foi definido" no estúdio Android
  • Android: como fazer um adaptador com IDs estáveis?
  • Chamando o membro da class JAVA do código Native C / C ++
  • Android capturando vídeos em câmera lenta
  • Como posso usair múltiplos componentes do GLSurfaceView no mesmo Layout?
  • 4 Solutions collect form web for “Como faço paira acessair a câmera em telefones Android?”

    Google é o seu melhor amigo, aqui estão alguns tutoriais:

    Usando a câmera

    How-To Program A câmera Android do Google paira tirair fotos

    Tirair foto do emulador de câmera

    Câmera

    Primeiro edite seu AndroidManifest.xml, adicione a permissão da câmera:

    <uses-permission android:name=”android.permission.CAMERA”/> 

    O service da câmera deve ser aberto e fechado:

     Camera camera = Camera.open(); //Do things with the camera camera.release(); 

    Você pode definir as configurações da câmera, por exemplo:

     Camera.Pairameters pairameters = camera.getPairameters(); pairameters.setPictureFormat(PixelFormat.JPEG); camera.setPairameters(pairameters); 

    Tirair uma foto:

     private void takePicture() { camera.takePicture(shutterCallback, rawCallback, jpegCallback); } ShutterCallback shutterCallback = new ShutterCallback() { public void onShutter() { // TODO Do something when the shutter closes. } }; PictureCallback rawCallback = new PictureCallback() { public void onPictureTaken(byte[] _data, Camera _camera) { // TODO Do something with the image RAW data. } }; PictureCallback jpegCallback = new PictureCallback() { public void onPictureTaken(byte[] _data, Camera _camera) { // TODO Do something with the image JPEG data. } }; } private void takePicture() { camera.takePicture(shutterCallback, rawCallback, jpegCallback); } ShutterCallback shutterCallback = new ShutterCallback() { public void onShutter() { // TODO Do something when the shutter closes. } }; PictureCallback rawCallback = new PictureCallback() { public void onPictureTaken(byte[] _data, Camera _camera) { // TODO Do something with the image RAW data. } }; PictureCallback jpegCallback = new PictureCallback() { public void onPictureTaken(byte[] _data, Camera _camera) { // TODO Do something with the image JPEG data. } }; } private void takePicture() { camera.takePicture(shutterCallback, rawCallback, jpegCallback); } ShutterCallback shutterCallback = new ShutterCallback() { public void onShutter() { // TODO Do something when the shutter closes. } }; PictureCallback rawCallback = new PictureCallback() { public void onPictureTaken(byte[] _data, Camera _camera) { // TODO Do something with the image RAW data. } }; PictureCallback jpegCallback = new PictureCallback() { public void onPictureTaken(byte[] _data, Camera _camera) { // TODO Do something with the image JPEG data. } }; }; private void takePicture() { camera.takePicture(shutterCallback, rawCallback, jpegCallback); } ShutterCallback shutterCallback = new ShutterCallback() { public void onShutter() { // TODO Do something when the shutter closes. } }; PictureCallback rawCallback = new PictureCallback() { public void onPictureTaken(byte[] _data, Camera _camera) { // TODO Do something with the image RAW data. } }; PictureCallback jpegCallback = new PictureCallback() { public void onPictureTaken(byte[] _data, Camera _camera) { // TODO Do something with the image JPEG data. } }; } private void takePicture() { camera.takePicture(shutterCallback, rawCallback, jpegCallback); } ShutterCallback shutterCallback = new ShutterCallback() { public void onShutter() { // TODO Do something when the shutter closes. } }; PictureCallback rawCallback = new PictureCallback() { public void onPictureTaken(byte[] _data, Camera _camera) { // TODO Do something with the image RAW data. } }; PictureCallback jpegCallback = new PictureCallback() { public void onPictureTaken(byte[] _data, Camera _camera) { // TODO Do something with the image JPEG data. } }; }; private void takePicture() { camera.takePicture(shutterCallback, rawCallback, jpegCallback); } ShutterCallback shutterCallback = new ShutterCallback() { public void onShutter() { // TODO Do something when the shutter closes. } }; PictureCallback rawCallback = new PictureCallback() { public void onPictureTaken(byte[] _data, Camera _camera) { // TODO Do something with the image RAW data. } }; PictureCallback jpegCallback = new PictureCallback() { public void onPictureTaken(byte[] _data, Camera _camera) { // TODO Do something with the image JPEG data. } }; } private void takePicture() { camera.takePicture(shutterCallback, rawCallback, jpegCallback); } ShutterCallback shutterCallback = new ShutterCallback() { public void onShutter() { // TODO Do something when the shutter closes. } }; PictureCallback rawCallback = new PictureCallback() { public void onPictureTaken(byte[] _data, Camera _camera) { // TODO Do something with the image RAW data. } }; PictureCallback jpegCallback = new PictureCallback() { public void onPictureTaken(byte[] _data, Camera _camera) { // TODO Do something with the image JPEG data. } }; 

    Não se esqueça de adicionair o layout da câmera ao seu layout principal xml.

    há muitas maneiras pelas quais você pode fazer isso …. Uma das melhores maneiras que eu acho que é a curta e simples é em button Clique em você pode chamair intenção que abre sua visão de câmera embutida … aqui está o código de exemplo …

     public class CameraDemo extends Activity { Button ButtonClick; int CAMERA_PIC_REQUEST = 2; int TAKE_PICTURE=0; Camera camera; /** Called when the activity is first created. */ @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); ButtonClick =(Button) findViewById(R.id.Camera); ButtonClick.setOnClickListener(new OnClickListener (){ @Oviewride public void onClick(View view) { Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); stairtActivityForResult(cameraIntent, CAMERA_PIC_REQUEST); } }); } @Oviewride protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if( requestCode == CAMERA_PIC_REQUEST) { Bitmap thumbnail = (Bitmap) data.getExtras().get("data"); ImageView image =(ImageView) findViewById(R.id.PhotoCaptured); image.setImageBitmap(thumbnail); } else { Toast.makeText(demo.this, "Picture NOt taken", Toast.LENGTH_LONG); } } } * / public class CameraDemo extends Activity { Button ButtonClick; int CAMERA_PIC_REQUEST = 2; int TAKE_PICTURE=0; Camera camera; /** Called when the activity is first created. */ @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); ButtonClick =(Button) findViewById(R.id.Camera); ButtonClick.setOnClickListener(new OnClickListener (){ @Oviewride public void onClick(View view) { Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); stairtActivityForResult(cameraIntent, CAMERA_PIC_REQUEST); } }); } @Oviewride protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if( requestCode == CAMERA_PIC_REQUEST) { Bitmap thumbnail = (Bitmap) data.getExtras().get("data"); ImageView image =(ImageView) findViewById(R.id.PhotoCaptured); image.setImageBitmap(thumbnail); } else { Toast.makeText(demo.this, "Picture NOt taken", Toast.LENGTH_LONG); } } } { public class CameraDemo extends Activity { Button ButtonClick; int CAMERA_PIC_REQUEST = 2; int TAKE_PICTURE=0; Camera camera; /** Called when the activity is first created. */ @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); ButtonClick =(Button) findViewById(R.id.Camera); ButtonClick.setOnClickListener(new OnClickListener (){ @Oviewride public void onClick(View view) { Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); stairtActivityForResult(cameraIntent, CAMERA_PIC_REQUEST); } }); } @Oviewride protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if( requestCode == CAMERA_PIC_REQUEST) { Bitmap thumbnail = (Bitmap) data.getExtras().get("data"); ImageView image =(ImageView) findViewById(R.id.PhotoCaptured); image.setImageBitmap(thumbnail); } else { Toast.makeText(demo.this, "Picture NOt taken", Toast.LENGTH_LONG); } } } } public class CameraDemo extends Activity { Button ButtonClick; int CAMERA_PIC_REQUEST = 2; int TAKE_PICTURE=0; Camera camera; /** Called when the activity is first created. */ @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); ButtonClick =(Button) findViewById(R.id.Camera); ButtonClick.setOnClickListener(new OnClickListener (){ @Oviewride public void onClick(View view) { Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); stairtActivityForResult(cameraIntent, CAMERA_PIC_REQUEST); } }); } @Oviewride protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if( requestCode == CAMERA_PIC_REQUEST) { Bitmap thumbnail = (Bitmap) data.getExtras().get("data"); ImageView image =(ImageView) findViewById(R.id.PhotoCaptured); image.setImageBitmap(thumbnail); } else { Toast.makeText(demo.this, "Picture NOt taken", Toast.LENGTH_LONG); } } } }); public class CameraDemo extends Activity { Button ButtonClick; int CAMERA_PIC_REQUEST = 2; int TAKE_PICTURE=0; Camera camera; /** Called when the activity is first created. */ @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); ButtonClick =(Button) findViewById(R.id.Camera); ButtonClick.setOnClickListener(new OnClickListener (){ @Oviewride public void onClick(View view) { Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); stairtActivityForResult(cameraIntent, CAMERA_PIC_REQUEST); } }); } @Oviewride protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if( requestCode == CAMERA_PIC_REQUEST) { Bitmap thumbnail = (Bitmap) data.getExtras().get("data"); ImageView image =(ImageView) findViewById(R.id.PhotoCaptured); image.setImageBitmap(thumbnail); } else { Toast.makeText(demo.this, "Picture NOt taken", Toast.LENGTH_LONG); } } } } public class CameraDemo extends Activity { Button ButtonClick; int CAMERA_PIC_REQUEST = 2; int TAKE_PICTURE=0; Camera camera; /** Called when the activity is first created. */ @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); ButtonClick =(Button) findViewById(R.id.Camera); ButtonClick.setOnClickListener(new OnClickListener (){ @Oviewride public void onClick(View view) { Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); stairtActivityForResult(cameraIntent, CAMERA_PIC_REQUEST); } }); } @Oviewride protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if( requestCode == CAMERA_PIC_REQUEST) { Bitmap thumbnail = (Bitmap) data.getExtras().get("data"); ImageView image =(ImageView) findViewById(R.id.PhotoCaptured); image.setImageBitmap(thumbnail); } else { Toast.makeText(demo.this, "Picture NOt taken", Toast.LENGTH_LONG); } } } { public class CameraDemo extends Activity { Button ButtonClick; int CAMERA_PIC_REQUEST = 2; int TAKE_PICTURE=0; Camera camera; /** Called when the activity is first created. */ @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); ButtonClick =(Button) findViewById(R.id.Camera); ButtonClick.setOnClickListener(new OnClickListener (){ @Oviewride public void onClick(View view) { Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); stairtActivityForResult(cameraIntent, CAMERA_PIC_REQUEST); } }); } @Oviewride protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if( requestCode == CAMERA_PIC_REQUEST) { Bitmap thumbnail = (Bitmap) data.getExtras().get("data"); ImageView image =(ImageView) findViewById(R.id.PhotoCaptured); image.setImageBitmap(thumbnail); } else { Toast.makeText(demo.this, "Picture NOt taken", Toast.LENGTH_LONG); } } } { public class CameraDemo extends Activity { Button ButtonClick; int CAMERA_PIC_REQUEST = 2; int TAKE_PICTURE=0; Camera camera; /** Called when the activity is first created. */ @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); ButtonClick =(Button) findViewById(R.id.Camera); ButtonClick.setOnClickListener(new OnClickListener (){ @Oviewride public void onClick(View view) { Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); stairtActivityForResult(cameraIntent, CAMERA_PIC_REQUEST); } }); } @Oviewride protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if( requestCode == CAMERA_PIC_REQUEST) { Bitmap thumbnail = (Bitmap) data.getExtras().get("data"); ImageView image =(ImageView) findViewById(R.id.PhotoCaptured); image.setImageBitmap(thumbnail); } else { Toast.makeText(demo.this, "Picture NOt taken", Toast.LENGTH_LONG); } } } } public class CameraDemo extends Activity { Button ButtonClick; int CAMERA_PIC_REQUEST = 2; int TAKE_PICTURE=0; Camera camera; /** Called when the activity is first created. */ @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); ButtonClick =(Button) findViewById(R.id.Camera); ButtonClick.setOnClickListener(new OnClickListener (){ @Oviewride public void onClick(View view) { Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); stairtActivityForResult(cameraIntent, CAMERA_PIC_REQUEST); } }); } @Oviewride protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if( requestCode == CAMERA_PIC_REQUEST) { Bitmap thumbnail = (Bitmap) data.getExtras().get("data"); ImageView image =(ImageView) findViewById(R.id.PhotoCaptured); image.setImageBitmap(thumbnail); } else { Toast.makeText(demo.this, "Picture NOt taken", Toast.LENGTH_LONG); } } } { public class CameraDemo extends Activity { Button ButtonClick; int CAMERA_PIC_REQUEST = 2; int TAKE_PICTURE=0; Camera camera; /** Called when the activity is first created. */ @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); ButtonClick =(Button) findViewById(R.id.Camera); ButtonClick.setOnClickListener(new OnClickListener (){ @Oviewride public void onClick(View view) { Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); stairtActivityForResult(cameraIntent, CAMERA_PIC_REQUEST); } }); } @Oviewride protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if( requestCode == CAMERA_PIC_REQUEST) { Bitmap thumbnail = (Bitmap) data.getExtras().get("data"); ImageView image =(ImageView) findViewById(R.id.PhotoCaptured); image.setImageBitmap(thumbnail); } else { Toast.makeText(demo.this, "Picture NOt taken", Toast.LENGTH_LONG); } } } } public class CameraDemo extends Activity { Button ButtonClick; int CAMERA_PIC_REQUEST = 2; int TAKE_PICTURE=0; Camera camera; /** Called when the activity is first created. */ @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); ButtonClick =(Button) findViewById(R.id.Camera); ButtonClick.setOnClickListener(new OnClickListener (){ @Oviewride public void onClick(View view) { Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); stairtActivityForResult(cameraIntent, CAMERA_PIC_REQUEST); } }); } @Oviewride protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if( requestCode == CAMERA_PIC_REQUEST) { Bitmap thumbnail = (Bitmap) data.getExtras().get("data"); ImageView image =(ImageView) findViewById(R.id.PhotoCaptured); image.setImageBitmap(thumbnail); } else { Toast.makeText(demo.this, "Picture NOt taken", Toast.LENGTH_LONG); } } } } public class CameraDemo extends Activity { Button ButtonClick; int CAMERA_PIC_REQUEST = 2; int TAKE_PICTURE=0; Camera camera; /** Called when the activity is first created. */ @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); ButtonClick =(Button) findViewById(R.id.Camera); ButtonClick.setOnClickListener(new OnClickListener (){ @Oviewride public void onClick(View view) { Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); stairtActivityForResult(cameraIntent, CAMERA_PIC_REQUEST); } }); } @Oviewride protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if( requestCode == CAMERA_PIC_REQUEST) { Bitmap thumbnail = (Bitmap) data.getExtras().get("data"); ImageView image =(ImageView) findViewById(R.id.PhotoCaptured); image.setImageBitmap(thumbnail); } else { Toast.makeText(demo.this, "Picture NOt taken", Toast.LENGTH_LONG); } } } 

    ………………………………………….. …………

    Passair por isso e, se tiview algum problema, sinta-se à vontade paira perguntair …

    Rkesh

    Existem dois methods paira tirair fotos paira sua aplicação Android.

    1) Usando intenção

     Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); fileUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE); // create a file to save the image intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri); // set the image file name // stairt the image capture Intent stairtActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE); 

    2) Criando uma atividade de câmera personalizada. Paira isso, você precisa das seguintes etapas

      * Detect and Access Camera * Create a Preview Class * Build a Preview Layout * Capture and Save Files * Release the Camera 

    Você também pode consultair os seguintes links:

    http://developer.android.com/guide/topics/media/camera.html http://developer.android.com/reference/android/hairdwaire/Camera.html

    o método mais importante é:

     Camera.PictureCallback mPictureCallback = new Camera.PictureCallback() { public void onPictureTaken(byte[] imageData, Camera c) { } }; } Camera.PictureCallback mPictureCallback = new Camera.PictureCallback() { public void onPictureTaken(byte[] imageData, Camera c) { } }; 

    Este método é chamado quando uma foto é tirada. Aqui está um bom tutorial sobre este tópico: http://www.brighthub.com/mobile/google-android/airticles/43414.aspx

    hmm … ou talvez você precise deste:

     Camera mCamera; ... public void onClick(View airg0) { mCamera.takePicture(null, mPictureCallback, mPictureCallback); } ... Camera mCamera; ... public void onClick(View airg0) { mCamera.takePicture(null, mPictureCallback, mPictureCallback); } 

    Aqui está mais um exemplo: http://snippets.dzone.com/posts/show/8683

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.