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:
Using java Syntax Highlighting
- private void getImage(String string) {
- if(!isCamBusy){
- isCamBusy = true;
- mCamera = Camera.open();
- cParams = mCamera.getParameters();
- cParams.setPictureSize(320, 240);
- cParams.setPictureFormat(PixelFormat.JPEG);
- mCamera.setParameters(cParams);
- ImageCaptureCallback iccb = new ImageCaptureCallback();
- mCamera.takePicture(null, null, iccb);
- }
- }
- public class ImageCaptureCallback implements PictureCallback{
- @Override
- public void onPictureTaken(byte[] data, Camera camera) {
- try{
- String dirpath = Environment.getExternalStorageDirectory().getAbsolutePath().concat("/1206");
- Bitmap img = BitmapFactory.decodeByteArray(data, 0, data.length);
- Random rgen = new Random();
- int rnum = rgen.nextInt(10000);
- String fname = rnum+".jpg";
- File file = new File(dirpath, fname);
- file.createNewFile();
- fos = new FileOutputStream(file);
- img.compress(CompressFormat.JPEG, 100, fos);
- fos.flush();
- fos.close();
- }catch(Exception e){
- e.printStackTrace();
- }
- camera.release();
- isCamBusy = false;
- }
- };
Parsed in 0.035 seconds, using GeSHi 1.0.8.4
Can anybody point me something. Thanks in advance, Ejder Yurdakul.

