Camera takes black picture

All your problems with Audio, Video and Images.

Camera takes black picture

Postby eyurdakul » Thu Mar 04, 2010 1:37 pm

Hi everybody,

i am trying to take a picture without preview and save it in the SD card. Everything works fine but the image is black. Here is my getImage function:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. private void getImage(String string) {
  3.  
  4.                 if(!isCamBusy){
  5.  
  6.                         isCamBusy = true;
  7.  
  8.                         mCamera = Camera.open();
  9.  
  10.                         cParams = mCamera.getParameters();
  11.  
  12.                         cParams.setPictureSize(320, 240);
  13.  
  14.                         cParams.setPictureFormat(PixelFormat.JPEG);
  15.  
  16.                         mCamera.setParameters(cParams);
  17.  
  18.                         ImageCaptureCallback iccb = new ImageCaptureCallback();
  19.  
  20.                         mCamera.takePicture(null, null, iccb);
  21.  
  22.                 }
  23.  
  24.         }
  25.  
  26.         public class  ImageCaptureCallback implements PictureCallback{
  27.  
  28.  
  29.  
  30.              @Override
  31.  
  32.              public void onPictureTaken(byte[] data, Camera camera) {
  33.  
  34.                  
  35.  
  36.                  try{
  37.  
  38.                          String dirpath = Environment.getExternalStorageDirectory().getAbsolutePath().concat("/1206");
  39.  
  40.                          Bitmap img = BitmapFactory.decodeByteArray(data, 0, data.length);
  41.  
  42.                          
  43.  
  44.                          Random rgen = new Random();
  45.  
  46.                          int rnum = rgen.nextInt(10000);
  47.  
  48.                          String fname = rnum+".jpg";
  49.  
  50.                          
  51.  
  52.                          File file = new File(dirpath, fname);
  53.  
  54.                          file.createNewFile();
  55.  
  56.                          fos = new FileOutputStream(file);
  57.  
  58.                          img.compress(CompressFormat.JPEG, 100, fos);
  59.  
  60.                          fos.flush();
  61.  
  62.                          fos.close();
  63.  
  64.                  }catch(Exception e){
  65.  
  66.                          e.printStackTrace();
  67.  
  68.                  }
  69.  
  70.                  camera.release();
  71.  
  72.                  isCamBusy = false;
  73.  
  74.              }
  75.  
  76.  
  77.  
  78.         };
  79.  
  80.  
Parsed in 0.036 seconds, using GeSHi 1.0.8.4


Can anybody point me something. Thanks in advance, Ejder Yurdakul.
eyurdakul
Junior Developer
Junior Developer
 
Posts: 13
Joined: Thu Mar 04, 2010 1:19 pm

Top

Postby eyurdakul » Thu Mar 04, 2010 5:10 pm

Wel, it seems you get a black image with cupcake, if you don't use a preview. This works fine on emulator tough.
So the question is little changed. Now i have a broadcast receiver which starts a service after boot. This service should be able to take a picture without a preview. I've created a surface view with and surface holder listener but i can't get onsurfacecreated fired. Do i have to set this view as main view and focus. Do you have any suggestion or work around for this problem?
eyurdakul
Junior Developer
Junior Developer
 
Posts: 13
Joined: Thu Mar 04, 2010 1:19 pm

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: No registered users and 14 guests