Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with result orientation #20

Open
alyadins opened this issue Apr 5, 2016 · 7 comments
Open

Problem with result orientation #20

alyadins opened this issue Apr 5, 2016 · 7 comments

Comments

@alyadins
Copy link

alyadins commented Apr 5, 2016

I have problem with front camera on some devices.
On meizu and sony all is ok.
On some chineses devices rotationMatrix is wrong.
screenshot_2016-04-05-21-13-28 Sony
screenshot_2016-04-05-21-12-33 Ulefone Power

@alyadins
Copy link
Author

alyadins commented Apr 6, 2016

Initialization

    RxCameraConfigChooser chooser = RxCameraConfigChooser.obtain();
        if (getPresenter().isFront()) {
            chooser.useFrontCamera();
        } else {
            chooser.useBackCamera();
        }
        chooser.setAutoFocus(true)
                .setPreferPreviewSize(new Point(640, 480))
                .setHandleSurfaceEvent(true);
        config = chooser.get();
        RxCamera.open(this, config)
                .flatMap(rxCamera -> {
                    this.rxCamera = rxCamera;
                    return rxCamera.bindTexture(textureView);
                })
                .flatMap(RxCamera::startPreview)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(rxCamera -> {
                    PhotoActivity.this.rxCamera = rxCamera;
                });

requesting

    if (rxCamera.isOpenCamera()) {
            rxCamera.request().takePictureRequest(true,
                    () -> {
                    },
                    1080,
                    1920,
                    ImageFormat.JPEG,
                    false)
                    .subscribeOn(Schedulers.io())
                    .observeOn(Schedulers.io())
                    .subscribe(rxCameraData -> {
                        if (getPresenter().isFront()) {
                            getPresenter().createBitmapFromFront(rxCameraData.cameraData, rxCameraData.rotateMatrix);
                        } else {
                            getPresenter().createBitmapFromBack(rxCameraData.cameraData, rxCameraData.rotateMatrix);
                        }
                    });
        }

@ragnraok
Copy link
Owner

ragnraok commented Apr 9, 2016

that mens the orientation retrieve from CameraInfo is wrong, can you show me the result of RxCameraConfig.toString?

@alyadins
Copy link
Author

Nexus 5
RxCameraConfig isFaceCamera: true, currentCameraId: 1, preferPreviewSize: Point(640, 480), minPreferPreviewFrameRate: -1, maxPreferPreviewFrameRate: -1, previewFormat: -1, displayOrientation: 90, isAutoFocus: truepreviewBufferSize: -1, isHandleSurfaceEvent: true, cameraOrien: 270,

Ulefone
RxCameraConfig isFaceCamera: true, currentCameraId: 1, preferPreviewSize: Point(640, 480), minPreferPreviewFrameRate: -1, maxPreferPreviewFrameRate: -1, previewFormat: -1, displayOrientation: 90, isAutoFocus: truepreviewBufferSize: -1, isHandleSurfaceEvent: true, cameraOrien: 270,

They are the same...

@ragnraok
Copy link
Owner

It seem that I need some special fix for this machine, I will find a way to fix this, thanks for your report

@milis92
Copy link

milis92 commented Sep 17, 2016

This issue is happening because of mirroring mode on some devices. Solution for this can be sorted out with https://gist.github.com/9re/1990019, but it depens on device's camera software populating exif information and should work in most of the cases...

@ragnraok
Copy link
Owner

@f0restgump92 the exif information only help for saved images, and can't fix the camera preview

@somranizaineb
Copy link

if (camera.isOpenCamera()) {
camera.request().takePictureRequest(false, new Func() {
@OverRide
public void call() {

            }
        }, 480, 640, ImageFormat.JPEG, false).subscribe(new Action1<RxCameraData>() {
            @Override
            public void call(RxCameraData rxCameraData) {
                File pictureFileDir = getDir();

                if (!pictureFileDir.exists() && !pictureFileDir.mkdirs()) {

                    return;
                }

                SimpleDateFormat dateFormat = new SimpleDateFormat("yyyymmddhhmmss");
                String date = dateFormat.format(new Date());
                String photoFile = "Pic" + date + ".jpg";

                String filename = pictureFileDir.getPath() + File.separator + photoFile;

                File pictureFile = new File(filename);
                Bitmap bitmap = BitmapFactory.decodeByteArray(rxCameraData.cameraData, 0, rxCameraData.cameraData.length);

                if (camera.getConfig().isFaceCamera) {
                    //to turn face picture taken 
                    Matrix mat = new Matrix();
                    mat.postRotate(-90);
                    mat.preScale(1.0f, -1.0f);

                    bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(),
                            mat, false);
                } else {
                    

                    Matrix mat = new Matrix();
                    mat.postRotate(-90);
                    mat.preScale(1.0f, -1.0f);
                    bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(),
                            rxCameraData.rotateMatrix, false);
                }

                try {
                    pictureFile.createNewFile();
                    FileOutputStream fos = new FileOutputStream(pictureFile);
                    bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos);
                    fos.close();

                    Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
                    Uri contentUri = Uri.fromFile(pictureFile);
                    imageUrls.add(contentUri.toString());
                    mediaScanIntent.setData(contentUri);
                    mActivity.sendBroadcast(mediaScanIntent);


                } catch (IOException e) {
                    e.printStackTrace();
                }

            }
        });
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants