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

Save Image orientation #4

Open
jackeykabra opened this issue Jul 9, 2018 · 23 comments
Open

Save Image orientation #4

jackeykabra opened this issue Jul 9, 2018 · 23 comments

Comments

@jackeykabra
Copy link

jackeykabra commented Jul 9, 2018

Hello Siralam,

I have used your custom camera library it is working nice and perfect but my QA has found one issue. it does not issue from your side but I want to get this type of functionality in your library.

When we click native camera image in portrait mode you will be got perfect as the 90-degree image but
in your library, it perfectly works and reveals 90-degree.

but when we click native camera image in landscape mode you will be got perfect as the 90-degree image but in your library, it not reveals 90-degree it displays another degree image. I am giving screenshot what am I getting and what I want.

I think you will understand my point. I want to 90-degree capture pictures save in sd card from landscape or portrait mode.

I changed code in "CameraViewImpl.class", but no effect to "CameraActivity.java" files
like :
cameraView.setOnPictureTakenListener(new CameraViewImpl.OnPictureTakenListener() {
@OverRide
public void onPictureTaken(Bitmap bitmap, int rotationDegrees) {
startSavingPhoto(bitmap, rotationDegrees);
}
});

in this method every time I am getting rotationDegrees = -90 value.

I don't know I am wrong or right can you please help me with this solution.
Whatever mode we click image we save the 90-Degree image. Thank you in advance.

@jackeykabra jackeykabra changed the title Save Image same orientation Save Image orientation Jul 9, 2018
@siralam
Copy link
Owner

siralam commented Jul 9, 2018

I am sorry but I am not sure about what you mean. Please clarify the below 2 questions:

(1) Does your activity fixed in portrait mode?
(2) if the answer to question 1 is yes, do you mean rotationDegrees are always -90 no matter how you hold your device?

@jackeykabra
Copy link
Author

jackeykabra commented Jul 9, 2018

  1. Yes, it's in portrait mode.
  2. I hold landscape and portrait then taken picture. can you check mobile camera it gives same orientation. in this library, I attached screenshots as above of whatever angle from clicking image we will get image same orientation like 90.

@siralam
Copy link
Owner

siralam commented Jul 9, 2018

I cannot reproduce this. And actually the device orientation is detected using sensors. If in case your device's sensor is broken / does not even have a sensor, the orientation will not work. May I know your device model?

@jackeykabra
Copy link
Author

For example, I have taken a picture in landscape mode so image saved in that orientation means landscape. But I need that image in 90 degrees just like a taken picture in portrait mode.

@siralam
Copy link
Owner

siralam commented Jul 9, 2018

I have taken a picture in landscape mode

That's why I asked the 1st question first. "Taken a picture in landscape mode" can mean "The activity is landscape" or "The device is held in landscape". Which one do you mean?

@jackeykabra
Copy link
Author

Camera activity is in portrait mode but when we change our device orientation for click the photo in camera view then photo clicked in that orientation.

@siralam
Copy link
Owner

siralam commented Jul 9, 2018

Hmmm.... I don't understand (in the sense of language) what do you mean by "for click the photo in camera view then photo clicked in that orientation"...

Is it possible for you to perform a screen recording?

@siralam
Copy link
Owner

siralam commented Jul 9, 2018

Arrrrrrrrrrrr I finally got what you mean!!!!!

@siralam
Copy link
Owner

siralam commented Jul 9, 2018

You mean, you want to take the photo when you hold your device in landscape,

So now the library will return a different orientation to you. So when you save the photo, the image has a longer width than height; but you still want to save the photo with shorter width than height, even if it does not look like what you see in the camera preview.

Am I correct?

(hmmm But this does not match what your screencap means)

@jackeykabra
Copy link
Author

jackeykabra commented Jul 9, 2018

screenshot_20180709-154920

I am attaching one image. This image there are two images I have set at bottom of camera view the 1st image I have a click in the portrait mode it's perfect. A 2ed image I have click landscape and it's save in landscape. but now I want to save 2ed image same as the 1st image.

means whatever mode you have click but we save 1st ways to save our image.

@jackeykabra
Copy link
Author

jackeykabra commented Jul 9, 2018

Are you understand my point?

Can you use your mobile default camera and take picture landscape and portrait then view in a gallery clicked images. Is it possible in this library? I have a check in Whatsup application it's work perfect.

@siralam
Copy link
Owner

siralam commented Jul 9, 2018

So this is a perfectly normal use case...

Try to use debugger and add a breakpoint to onPictureTaken.
And then take a picture while holding the device in different orientations.

Can you observe the value of rotationDegrees changes by 90 degrees?

If not, please tell me your device model.

If yes, this means you haven't implement your code to rotate the image to the orientation you want before saving it.

@jackeykabra
Copy link
Author

jackeykabra commented Jul 9, 2018

My device model is Moto g4 Plus.

I tried and debugger on onPictureTaken. I am get rotationDegrees value -90 every time form both orientations.

@siralam
Copy link
Owner

siralam commented Jul 9, 2018

Hmm. Strange.

Do you have other device to try? I want to try to find out if it is the problem of the model only. I cannot reproduce this on all my devices.

And may you also post your related code, all from onPictureTaken called to saving the photo?

@jackeykabra
Copy link
Author

jackeykabra commented Jul 9, 2018

Yes,

I tested in HTC One M9PLUS device and in this, it worked fine also changed rotation degrees value.
No change in use code:

private void startSavingPhoto(final Bitmap bitmap, final int rotationDegrees) {
        Observable.fromCallable(new Callable<Bitmap>() {
        @Override
        public Bitmap call() throws Exception {
            Matrix matrix = new Matrix();
            matrix.postRotate(-rotationDegrees);
            return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
        }
    }).map(new Function<Bitmap, String>() {
        @Override
        public String apply(Bitmap bitmap) throws Exception {
            return bitmapToFile(bitmap);
        }
    }).subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(new Consumer<String>() {
                @Override
                public void accept(String filePath) throws Exception {
                    if (filePath.isEmpty()) {
                        Toast.makeText(CameraActivity.this, "Save image file failed :(", Toast.LENGTH_SHORT).show();
                    } else {
                        notifyGallery(filePath);
                    }
                }
            });
}

what about Moto g4 Plus? can you find any solution in library code?

@siralam
Copy link
Owner

siralam commented Jul 9, 2018

I am afraid I can do nothing, given that the rotation degrees are originated directly from sensor; what I can conclude is the sensor is not working on your phone; or Moto g4 Plus simply not support it (Not likely).

@jackeykabra
Copy link
Author

jackeykabra commented Jul 10, 2018

In this library, it works perfectly in Moto g4 Plus I think it's helpful to you please find below URL.
https://github.com/CameraKit/camerakit-android.

Please try to optimize code using this library it's very helpful to me. thank you.

@siralam
Copy link
Owner

siralam commented Jul 10, 2018

The way I handle orientation is not the same as the library you mentioned. That library does not involve using sensor to detect orientation.

Before I changed to using sensor, I used the default method provided by the original google's CameraView; but I found that it does not work in some devices that I have.

Therefore I am not falling back to using the old method since it will break some of the good results in some devices that I already have.

I suggest you try fotoapparat. I think it is good enough as long as you do not need to use the frames. But I am not sure if they implement orientation using sensor as well.

@jackeykabra
Copy link
Author

Same issue I have found in the SM-T231 device.

I try Fotoapparat it will work in Moto g4 plus and HTC One M9PLUS device. but in the SM-T231 device, not view camera as well as orientation issue.

@siralam
Copy link
Owner

siralam commented Jul 10, 2018

I have searched SM-T231 on the internet and it seems it only has accelerometer but no magnetometer. I think that's why the orientation is not working.

And then I tried to search specs of Moto G4 Plus as well, and it looks like it does not have magnetometer either.

I did not realize that so many devices do not have a magnetometer but Android official document is telling people to use magnetometer to detect orientation.......

I will try to implement a different way to detect orientation in the future. But I might not have enough time recently... See if you can wait.

Thanks for your report!

@siralam
Copy link
Owner

siralam commented Jul 30, 2018

@jackeykabra I have rewritten the way of detecting orientation, but I don't have a device which does not have a magnetometer (compass) to test. Could you help trying again using 0.9.5?

@siralam siralam added Await verification Waiting for user to verify if the issue is resolved. and removed enhancement labels Jul 30, 2018
@jackeykabra
Copy link
Author

@siralam I have changed the code as you gave but it has not resolved in Moto g4.

@siralam
Copy link
Owner

siralam commented Jul 30, 2018

Hm.. Guess I have no other way to solve it then until I have a device without compass on hand. Sorry about that, I will mark a help wanted label here first.

@siralam siralam added help wanted and removed Await verification Waiting for user to verify if the issue is resolved. labels Jul 30, 2018
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

2 participants