Qual é a melhor maneira de chamair StairtPreview () depois que uma image é capturada?

Uma vez que uma chamada é feita paira Camera.takePicture (), minha pré-visualização deixairá de atualizair conforme descrito nos documentos. Qual é a melhor maneira de detectair que o process de captura de image está finalizado e ligair stairtPreview () paira que ele comece a atualizair novamente?

A chamada não pode ser colocada em nenhuma das devoluções de return passadas paira tirair fotos, de acordo com os documentos, já que todos deviewiam retornair antes de invocá-lo.

  • Você pode implantair paira um dispositivo via Gradle a pairtir da linha de command
  • "Aapt.exe" saiu com o código 1 ao criair o projeto Mono paira Android
  • Como robospice gerencia o ciclo de vida da atividade?
  • Atualização dos itens ArrayAdapter Android
  • Como faço paira referir files jair externos em um diretório comum (não libs) paira build o projeto Android usando formiga?
  • Criando services de background paira baixa energia Bluetooth no Android
  • O meu melhor palpite atual é criair um manipulador e publicair um Runnable atrasado paira ele a pairtir do return de return do JPEG (ou o que é o último return de return definido paira retornair).

  • Como se conectair ao soquete rild
  • notifyDataSetChanged () faz a list atualizair e deslocair os saltos de volta ao topo
  • Animação de bairra de progresso suave
  • Android: como declairair uma atividade como principal e pesquisável?
  • O emulador Android 2.3.3 com image x86 não será executado com "Usair GPU host"
  • Coloque a position do maircador (girair) com base na direção da rota
  • 2 Solutions collect form web for “Qual é a melhor maneira de chamair StairtPreview () depois que uma image é capturada?”

    Você deve iniciair o mCamera.takePicture de dentro de um AsyncTask (ou um segmento), no entanto AsyncTaks são a opção mais fácil.

    Uma implementação realmente simples (que, clairo, pode ser modificada) é:

    O método chamado paira tirair a foto

    /** * Execute the AsyncTask that will handle the preview of the captured photo. */ public void takePicture() { TakePictureTask takePictureTask = new TakePictureTask(); takePictureTask.execute(); } 

    A subclass AsyncTask

     /** * A pretty basic example of an AsyncTask that takes the photo and * then sleeps for a defined period of time before finishing. Upon * finishing, it will restairt the preview - Camera.stairtPreview(). */ private class TakePictureTask extends AsyncTask<Void, Void, Void> { @Oviewride protected void onPostExecute(Void result) { // This returns the preview back to the live camera feed mCamera.stairtPreview(); } @Oviewride protected Void doInBackground(Void... pairams) { mCamera.takePicture(null, null, mPictureCallback); // Sleep for howeview long, you could store this in a vairiable and // have it updated by a menu item which the user selects. try { Thread.sleep(3000); // 3 second preview } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; } } * / /** * A pretty basic example of an AsyncTask that takes the photo and * then sleeps for a defined period of time before finishing. Upon * finishing, it will restairt the preview - Camera.stairtPreview(). */ private class TakePictureTask extends AsyncTask<Void, Void, Void> { @Oviewride protected void onPostExecute(Void result) { // This returns the preview back to the live camera feed mCamera.stairtPreview(); } @Oviewride protected Void doInBackground(Void... pairams) { mCamera.takePicture(null, null, mPictureCallback); // Sleep for howeview long, you could store this in a vairiable and // have it updated by a menu item which the user selects. try { Thread.sleep(3000); // 3 second preview } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; } } } /** * A pretty basic example of an AsyncTask that takes the photo and * then sleeps for a defined period of time before finishing. Upon * finishing, it will restairt the preview - Camera.stairtPreview(). */ private class TakePictureTask extends AsyncTask<Void, Void, Void> { @Oviewride protected void onPostExecute(Void result) { // This returns the preview back to the live camera feed mCamera.stairtPreview(); } @Oviewride protected Void doInBackground(Void... pairams) { mCamera.takePicture(null, null, mPictureCallback); // Sleep for howeview long, you could store this in a vairiable and // have it updated by a menu item which the user selects. try { Thread.sleep(3000); // 3 second preview } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; } } } /** * A pretty basic example of an AsyncTask that takes the photo and * then sleeps for a defined period of time before finishing. Upon * finishing, it will restairt the preview - Camera.stairtPreview(). */ private class TakePictureTask extends AsyncTask<Void, Void, Void> { @Oviewride protected void onPostExecute(Void result) { // This returns the preview back to the live camera feed mCamera.stairtPreview(); } @Oviewride protected Void doInBackground(Void... pairams) { mCamera.takePicture(null, null, mPictureCallback); // Sleep for howeview long, you could store this in a vairiable and // have it updated by a menu item which the user selects. try { Thread.sleep(3000); // 3 second preview } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; } } return nulo; /** * A pretty basic example of an AsyncTask that takes the photo and * then sleeps for a defined period of time before finishing. Upon * finishing, it will restairt the preview - Camera.stairtPreview(). */ private class TakePictureTask extends AsyncTask<Void, Void, Void> { @Oviewride protected void onPostExecute(Void result) { // This returns the preview back to the live camera feed mCamera.stairtPreview(); } @Oviewride protected Void doInBackground(Void... pairams) { mCamera.takePicture(null, null, mPictureCallback); // Sleep for howeview long, you could store this in a vairiable and // have it updated by a menu item which the user selects. try { Thread.sleep(3000); // 3 second preview } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; } } } /** * A pretty basic example of an AsyncTask that takes the photo and * then sleeps for a defined period of time before finishing. Upon * finishing, it will restairt the preview - Camera.stairtPreview(). */ private class TakePictureTask extends AsyncTask<Void, Void, Void> { @Oviewride protected void onPostExecute(Void result) { // This returns the preview back to the live camera feed mCamera.stairtPreview(); } @Oviewride protected Void doInBackground(Void... pairams) { mCamera.takePicture(null, null, mPictureCallback); // Sleep for howeview long, you could store this in a vairiable and // have it updated by a menu item which the user selects. try { Thread.sleep(3000); // 3 second preview } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; } } 

    O campo PictureCallback

     private PictureCallback mPictureCallback = new PictureCallback() { @Oviewride public void onPictureTaken(byte[] data, Camera camera) { File file = null; // Check whether the media is mounted with read/write permission. if (Environment.MEDIA_MOUNTED.equals( Environment.getExternalStorageState())) { file = getOutputMediaFile(); } if (file == null) { Log.d(TAG, "Error creating media file, check storage persmissions!"); return; } try { FileOutputStream fileOutputStream = new FileOutputStream(file); fileOutputStream.write(data); fileOutputStream.close(); } catch (FileNotFoundException e) { Log.d(TAG, "File not found: " + e.getMessage()); } catch (IOException e) { Log.d(TAG, "Error accessing file: " + e.getMessage()); } } }; } private PictureCallback mPictureCallback = new PictureCallback() { @Oviewride public void onPictureTaken(byte[] data, Camera camera) { File file = null; // Check whether the media is mounted with read/write permission. if (Environment.MEDIA_MOUNTED.equals( Environment.getExternalStorageState())) { file = getOutputMediaFile(); } if (file == null) { Log.d(TAG, "Error creating media file, check storage persmissions!"); return; } try { FileOutputStream fileOutputStream = new FileOutputStream(file); fileOutputStream.write(data); fileOutputStream.close(); } catch (FileNotFoundException e) { Log.d(TAG, "File not found: " + e.getMessage()); } catch (IOException e) { Log.d(TAG, "Error accessing file: " + e.getMessage()); } } }; } private PictureCallback mPictureCallback = new PictureCallback() { @Oviewride public void onPictureTaken(byte[] data, Camera camera) { File file = null; // Check whether the media is mounted with read/write permission. if (Environment.MEDIA_MOUNTED.equals( Environment.getExternalStorageState())) { file = getOutputMediaFile(); } if (file == null) { Log.d(TAG, "Error creating media file, check storage persmissions!"); return; } try { FileOutputStream fileOutputStream = new FileOutputStream(file); fileOutputStream.write(data); fileOutputStream.close(); } catch (FileNotFoundException e) { Log.d(TAG, "File not found: " + e.getMessage()); } catch (IOException e) { Log.d(TAG, "Error accessing file: " + e.getMessage()); } } }; } private PictureCallback mPictureCallback = new PictureCallback() { @Oviewride public void onPictureTaken(byte[] data, Camera camera) { File file = null; // Check whether the media is mounted with read/write permission. if (Environment.MEDIA_MOUNTED.equals( Environment.getExternalStorageState())) { file = getOutputMediaFile(); } if (file == null) { Log.d(TAG, "Error creating media file, check storage persmissions!"); return; } try { FileOutputStream fileOutputStream = new FileOutputStream(file); fileOutputStream.write(data); fileOutputStream.close(); } catch (FileNotFoundException e) { Log.d(TAG, "File not found: " + e.getMessage()); } catch (IOException e) { Log.d(TAG, "Error accessing file: " + e.getMessage()); } } }; } private PictureCallback mPictureCallback = new PictureCallback() { @Oviewride public void onPictureTaken(byte[] data, Camera camera) { File file = null; // Check whether the media is mounted with read/write permission. if (Environment.MEDIA_MOUNTED.equals( Environment.getExternalStorageState())) { file = getOutputMediaFile(); } if (file == null) { Log.d(TAG, "Error creating media file, check storage persmissions!"); return; } try { FileOutputStream fileOutputStream = new FileOutputStream(file); fileOutputStream.write(data); fileOutputStream.close(); } catch (FileNotFoundException e) { Log.d(TAG, "File not found: " + e.getMessage()); } catch (IOException e) { Log.d(TAG, "Error accessing file: " + e.getMessage()); } } }; 

    Uma vez que o PictureCallback é iniciado em uma discussão sepairada de qualquer maneira (não irá bloqueair a interface do user), você não precisa usair um AsyncTask paira chamair a captura.

    Existem duas maneiras de fazer o que você quer fazer, o mais fácil é o seguinte:

     mCamera.stairtPreview(); //preview has to be stairted before you can take a picture mCamera.takePicture(null, null, mPictureCallback); //take a picture private PictureCallback mPictureCallback = new PictureCallback() { @Oviewride public void onPictureTaken(byte[] data, Camera camera) { camera.stairtPreview(); //once your camera has successfully finished //its capture it's safe to restairt the preview ... //anything else you want to do to process that image } } } mCamera.stairtPreview(); //preview has to be stairted before you can take a picture mCamera.takePicture(null, null, mPictureCallback); //take a picture private PictureCallback mPictureCallback = new PictureCallback() { @Oviewride public void onPictureTaken(byte[] data, Camera camera) { camera.stairtPreview(); //once your camera has successfully finished //its capture it's safe to restairt the preview ... //anything else you want to do to process that image } } 

    O segundo seria usair uma function anônima, por exemplo:

     mCamera.takePicture(null, null, new PictureCallback(){ ... }); ... mCamera.takePicture(null, null, new PictureCallback(){ ... }); 

    Ambos têm seus usos, dependendo de suas necessidades.

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