leojg
leojg

Reputation: 1186

S4 picture taken with custom camera is damage

I have this weird problem with my custom camera in the samsung S4. I all other devices I have tested it works, even on S4 mini.

The pictures taken looks like this:

enter image description here

There is these white stripes, what could these be?

The code does not do nothing weird, I think...

    @Override
    public void onPictureTaken(byte[] data, Camera myCamera) {
        File pictureFile = getOutputMediaFile(MEDIA_TYPE_IMAGE);
        if (pictureFile == null) {
            return;
        }

        try {
            FileOutputStream fos = new FileOutputStream(pictureFile);
            fos.write(data);
            fos.close();

            resizeImage(pictureFile.getPath());

            Intent returnIntent = new Intent();
            returnIntent.putExtra("path", pictureFile.getPath());
            setResult(RESULT_OK, returnIntent);
            finish();

        } catch (FileNotFoundException e) {
            //stuff
        } catch (IOException e) {
            //stuff
        }
    }

This is the resize, maybe has something to do:

private void resizeImage(String picturePath) {
    try {

        Bitmap bitmapIn = BitmapFactory.decodeFile(picturePath);

        Float w = (float) bitmapIn.getWidth();
        Float h = (float) bitmapIn.getHeight();

        Float aspect = w / h;

        if ((w * h) > 120000) {

            Bitmap bitmapOut;

            int neww = 400;

            if (w < h) {
                neww = 300;
            }

            Float newh = (h * neww) / w;

            bitmapOut = Bitmap.createScaledBitmap(bitmapIn, neww,
                    newh.intValue(), false);

            File file = getOutputMediaFile(MEDIA_TYPE_IMAGE);
            FileOutputStream fOut;

            fOut = new FileOutputStream(file);
            bitmapOut.compress(Bitmap.CompressFormat.JPEG, 60, fOut);
            fOut.flush();
            fOut.close();
            bitmapOut.recycle();
        } else {

        }

        bitmapIn.recycle();

    } catch (Exception e) {
        //stuff
    }
}

Upvotes: 1

Views: 238

Answers (2)

Mateus
Mateus

Reputation: 409

Maybe a solution for you...

I had the same problem and an interesting situation occurred in the Samsung S4!

The problem appear when the image size was much smaller than the size of the preview. For example: Preview Size: 1920 x 1080 and 640 x 480 Picture Size. So... the device set the Max resolution for picture and I don't know why...

To solve this problem, you must be combine both sizes: Preview Size and Picture Size. Its ok for me. With 2 sizes combined, the white stripes not appear! :-)

Upvotes: 0

quick release
quick release

Reputation: 288

Maybe you can solve this problem, using optimal picture size according to device.

What is the best camera parameters for android camera opened in surface view

Upvotes: 2

Related Questions