Take a picture. It comes as a byte array, which we collect in a bitmap and save to a file. But if you look at the resulting image, you will notice that it is slightly shifted to the right. Why is this happening and how to fix it?

The onPictureTaken method to which the array comes in:

public void onPictureTaken(byte[] paramArrayOfByte, Camera paramCamera) { imagesFolder.mkdir(); MyappDir.mkdir(); if (imagesFolder.listFiles().length == 0 | schet == null) { DataOutputStream out = null; Integer n = Integer.valueOf(1); try { out = new DataOutputStream(new FileOutputStream(schet)); out.writeInt(n.intValue()); out.close(); File image = new File(imagesFolder, "image_" + n + ".jpg"); Bitmap imageBmp = BitmapFactory.decodeByteArray(paramArrayOfByte, 0, paramArrayOfByte.length); Matrix matrix = new Matrix(); matrix.postRotate(90); imageBmp = imageBmp.createBitmap(imageBmp, 0, 0, 4128, 2322, matrix, true); FileOutputStream fos = new FileOutputStream(image); imageBmp.compress(Bitmap.CompressFormat.JPEG, 60, fos); fos.close(); galleryAddPic(); } catch (Exception e) { e.printStackTrace(); } } } 

    1 answer 1

    I am sure that it will stop moving if you remove this line.

     imageBmp = imageBmp.createBitmap(imageBmp, 0, 0, 4128, 2322, matrix, true); 

    Or, if it is necessary to turn it over, replace it with the following:

     imageBmp = imageBmp.createBitmap(imageBmp, 0, 0, imageBmp.getWidth(), imageBmp.getHeight(), matrix, true); 
    • So it turns out not the whole screen. - Nikitos
    • @Nikito, apparently, the screen resolution is not proportional to the resolution of the camera. Choose, or have to cut, or not on the whole screen. You can still try to stretch, for example - Vladyslav Matviienko
    • I took the width and height of the display of the smartphone, created a scaled bitmap, the image is stretched in height to the full screen and comes out too elongated in height. Can you tell me what else you can think of? - Nikitos
    • @ Nikitos I say - you can cut. - Vladyslav Matviienko
    • And how to cut? - Nikito