take picture without gui

All your problems with Audio, Video and Images.

take picture without gui

Postby suero » Tue Dec 21, 2010 4:24 pm

Hello, I'm trying to take pictures without using gui, the code gives no error but also does not work, I count on your help

Thanks
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package amee.org;
  2.  
  3. import java.io.FileNotFoundException;
  4. import java.io.FileOutputStream;
  5. import java.io.IOException;
  6.  
  7. import android.app.Activity;
  8. import android.hardware.Camera;
  9. import android.hardware.Camera.PictureCallback;
  10. import android.hardware.Camera.ShutterCallback;
  11. import android.os.Bundle;
  12. import android.util.Log;
  13.  
  14. public class main extends Activity {
  15.     /** Called when the activity is first created. */
  16.         private static final String TAG = "AMEE LD";
  17.         Camera camera;
  18.     @Override
  19.     public void onCreate(Bundle savedInstanceState) {
  20.         super.onCreate(savedInstanceState);
  21.         //setContentView(R.layout.main);
  22.         try
  23.         {
  24.                 Camera camera = Camera.open();
  25.                 Camera.Parameters parameters = camera.getParameters();
  26.                 camera.setParameters(parameters);
  27.                 camera.startPreview();
  28.                 camera.setPreviewDisplay(null);
  29.                 camera.takePicture(null, rawCallback,jpegCallback );
  30.                 Log.d(TAG,"Cam ABERTA");
  31.         }
  32.         catch (Exception e)
  33.         {
  34.                         Log.d(TAG,"ERRO" + e.getMessage());
  35.                 }
  36.     }
  37.     ShutterCallback shutterCallback = new ShutterCallback() {
  38.                 public void onShutter() {
  39.                         Log.d(TAG, "onShutter'd");
  40.                 }
  41.         };
  42.  
  43.         /** Handles data for raw picture */
  44.         PictureCallback rawCallback = new PictureCallback() {
  45.                 public void onPictureTaken(byte[] data, Camera camera) {
  46.                         Log.d(TAG, "onPictureTaken - raw");
  47.                 }
  48.         };
  49.  
  50.         /** Handles data for jpeg picture */
  51.         PictureCallback jpegCallback = new PictureCallback() {
  52.                 public void onPictureTaken(byte[] data, Camera camera) {
  53.                         FileOutputStream outStream = null;
  54.                         try {
  55.                                 camera.startPreview();
  56.                                 // write to local sandbox file system
  57. //                              outStream = CameraDemo.this.openFileOutput(String.format("%d.jpg", System.currentTimeMillis()), 0);    
  58.                                 // Or write to sdcard
  59.                                 outStream = new FileOutputStream(String.format("/sdcard/%d.jpg", System.currentTimeMillis())); 
  60.                                 outStream.write(data);
  61.                                 outStream.close();
  62.                                 Log.d(TAG, "onPictureTaken - wrote bytes: " + data.length);
  63.                         } catch (FileNotFoundException e) {
  64.                                 e.printStackTrace();
  65.                         } catch (IOException e) {
  66.                                 e.printStackTrace();
  67.                         } finally {
  68.                                 camera.stopPreview();
  69.                                 camera.release();
  70.                         }
  71.                         Log.d(TAG,"onPictureTaken - jpeg");
  72.                 }
  73.         };
  74.        
  75. }
Parsed in 0.041 seconds, using GeSHi 1.0.8.4
suero
Freshman
Freshman
 
Posts: 3
Joined: Tue Dec 21, 2010 2:56 pm

Top

Re: take picture without gui

Postby suero » Mon Dec 27, 2010 2:43 pm

I forgot to give written permission for the card

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>


but now another problem in the emulator works perfectly, but the device does not always
suero
Freshman
Freshman
 
Posts: 3
Joined: Tue Dec 21, 2010 2:56 pm

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: No registered users and 11 guests