Question

I am creating a program that uses twice the takepicture function, like this:

mCamera.takePicture(null, null, mPicture);

But only once it enter the PictureCallback loop:

private PictureCallback mPicture = new PictureCallback(){
//  Bitmap readyToGo;
    @Override
    public void onPictureTaken(byte[] data, Camera camera){
        Log.d(TAG, "entrei no picture callback");
        //-----OUT OF MEMORY ERROR


        pictureFile = getOutputMediaFile(MEDIA_TYPE_IMAGE);
        mPreview.setDrawingCacheEnabled(true);
        mPreview.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_AUTO);
        BitmapFactory.Options options = new BitmapFactory.Options(); 
        //options.inPurgeable = true;
        //options.inInputShareable = true;
        options.inJustDecodeBounds = true;
        options.inSampleSize = 5; 
        options.inJustDecodeBounds = false;

        Bitmap bitmap = mPreview.getDrawingCache();
        //---------------------------------------------------

        bmp = BitmapFactory.decodeByteArray(data, 0, data.length);  

            //combine the two bitmaps!!!!-------------
        Log.d("main", "antes overlay");
        combination = overlay(bmp, bitmap);
        Log.d("main", "depois overlay");


    //------------------ROTATION---------------------


        if(pictureFile == null)
        {
            Log.d(TAG, "Error creating media file, check storages permissions. ");
            return;
        }
        try
        {
            ExifInterface exif = new ExifInterface(pictureFile.getAbsolutePath());     //Since API Level 5
            String exifOrientation = exif.getAttribute(ExifInterface.TAG_ORIENTATION);
            Log.d("main", "exif orientation= "+exifOrientation);

            FileOutputStream fos = new FileOutputStream(pictureFile);
            Log.d(TAG, "ALO!!!");
            combination.compress(CompressFormat.JPEG, 100, fos);//troquei bitmap por combination
            fos.flush();
            fos.close();




        //------------------------------        
        clearBitmap(combination);
        clearBitmap(bmp);

        //------------------------------
        }
        catch(FileNotFoundException e)
        {
            Log.d(TAG, "File not found: "+e.getMessage());
        }
        catch(IOException e)
        {
            Log.d(TAG, "Error accessing file: "+e.getMessage());
        }
    }
};

Does anyobody know what happen, can I call it twice?

Was it helpful?

Solution

call thread to pause for 2 seconds and then recall it

or You can use your above code with this picture callback

public void takeSnapPhoto() {
camera.setOneShotPreviewCallback(new Camera.PreviewCallback() {
    @Override
    public void onPreviewFrame(byte[] data, Camera camera) {
        Camera.Parameters parameters = camera.getParameters();
        int format = parameters.getPreviewFormat();
        //YUV formats require more conversion
        if (format == ImageFormat.NV21 || format == ImageFormat.YUY2 || format == ImageFormat.NV16) {
            int w = parameters.getPreviewSize().width;
            int h = parameters.getPreviewSize().height;
            // Get the YuV image
            YuvImage yuv_image = new YuvImage(data, format, w, h, null);
            // Convert YuV to Jpeg
            Rect rect = new Rect(0, 0, w, h);
            ByteArrayOutputStream output_stream = new ByteArrayOutputStream();
            yuv_image.compressToJpeg(rect, 100, output_stream);
            byte[] byt = output_stream.toByteArray();
            FileOutputStream outStream = null;
            try {
                // Write to SD Card
                File file = createFileInSDCard(FOLDER_PATH, "Image_"+System.currentTimeMillis()+".jpg");
                //Uri uriSavedImage = Uri.fromFile(file);
                outStream = new FileOutputStream(file);
                outStream.write(byt);
                outStream.close();
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
            }
        }
    }
}); }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top