Search code examples
androidandroid-5.0-lollipopartifacts

Android Lollipop Camera.takePicture artifact


I faced weird issue using Nexus 5 with Android 5.0.1. I have a camera app, which has capture button, that captures frame from SurfacePreview and saves it to file:

public void takePicture(final Context context) {
    PictureCallback pictureCallback = new PictureCallback() {

        @Override
        public void onPictureTaken(byte[] data, Camera camera) {
            File pictureFile = StorageUtils.getOutputMediaFile(context, mIsForeside, null);
            if (pictureFile == null) {
                return;
            }
            InputStream is = new ByteArrayInputStream(data);    
            Bitmap bmp = BitmapFactory.decodeStream(is);
            FileOutputStream out = null;
            try {
                out = new FileOutputStream(pictureFile);
                bmp.compress(Bitmap.CompressFormat.PNG, 100, out);
            } catch (Exception e) {
            } finally {
                try {
                    out.close();
                } catch (Throwable ignore) {

                }
            }
            mOnPictureTakenListener.OnPictureTaken(pictureFile.getAbsolutePath());
        }
    };

    mCamera.takePicture(null, null, pictureCallback);
}

This code works just fine on Nexus 5 running Android 4.4, but on Nexus with Android 5.0.1 I see following artifact:

Photo with artifact

Has anyone aware of this issue?


Solution

  • Did you try to save data byte array into JPEG file, without bitmap converting?

    Since android 5, google introduce new camera API. May be you should try to use it?