dankito / RichTextEditor

Rich text WYSIWYG editor for Android and JavaFX
Apache License 2.0
92 stars 36 forks source link

Orientation problem & bug of the inserted portrait image & How to set descending order in image picker? #12

Closed applehong5013 closed 5 years ago

applehong5013 commented 5 years ago

Problem 1 : The image orientation is not correct on portrait image, when you choose or insert the portrait image, the image will become landscape.

Problem 2 : How to sort the date created by descending order in image picker. Example, There are a lot of image in my gallery, I can select the latest image from currently taken and no need to scroll a lot to get my image.

I have the portrait image in my gallery as below: screenshot_20181031-095511_gallery

When I want to insert the image and it show in the directory as below: 20181031_095716

After inserted image it show in the editor as below : 20181031_095814

dankito commented 5 years ago

This was a bit hard to figure out, as i can only guess what the problem is?

I guess the issue is similar to that one here that the image is actually rotated and the correct rotation must be read from EXIF data: https://stackoverflow.com/questions/31925712/android-getting-an-image-from-gallery-comes-rotated.

For the image picker this was quite easy to fix with the code from above Stackoverflow question.

For the editor (which runs in an embedded WebView) this was much harder, as the Android WebView doesn't support the image-rotation CSS value (https://developer.mozilla.org/en-US/docs/Web/CSS/image-orientation) and there's no way to set orientation directly on \ tag.

I fixed it now by reading image's orientation in Android and passing its rotation value on to JavaScript.

Just pushed version 2.0.4 with this fix to Maven Central.

Please check if this fixes your issue and if so close this ticket.

Otherwise please provide me an example image so that i can reproduce this issue and see what's going on in code.

applehong5013 commented 5 years ago

Thank you. Currently the image orientation problem is solve on the image picker after I update to version 2.0.4.

There still have issue of the image orientation still occur at the editor site. The image orientation is not correct in the editor.

dankito commented 5 years ago

The curious thing is, i'm using the same rotation detection code for the image picker and the editor.

Is the image in the editor now rotated to the other side (to the right instead of to the left)?

As i tested it only with a 180° rotated image, and that one has been working. May i did a mistake in the insertion code for images rotated by 90° and 270°.

If not, could you please provide me your example image (that one with the ice cream cone)? Then i can see what's going on in code that it gets inserted incorrectly.

dankito commented 5 years ago

I may now found the issue.

Could you please check if it's working now with version 2.0.6?

applehong5013 commented 5 years ago

The ice cream cone image below :D

20180924_153739

The problem still same, the orientation of the image (ice cream cone) in the editor is still the same after updated to 2.0.6. The original image (ice cream cone) is portrait, and when in the editor is not portrait.

applehong5013 commented 5 years ago

I no idea why this happen on github too lol, but it should be portrait and not landscape.

The image below I was use snipping tool to snap the image that open in Photos(Window 10 default photo software use to open any image)

screenshow

The image below is the image properties: As we can see the height is 4032px, and width is 3024px. Which mean the image(ice cream cone ) should not be landscape.

screenshow1

dankito commented 5 years ago

Ok, found the issue (was an Android specific one, on JavaFX it has been working).

Just pushed version 2.0.7 with the fix to Maven Central. As always, in at maximum two hours it should be publicly visible.

The issue, why it got displayed in landscape in GitHub and in RichTextEditor, is, that Samsung cameras save images in landscape mode and just set in EXIF meta data the 'Orientation' flag with tells image's real orientation.

So if an application doesn't read the EXIF meta data and corrects image's rotation, well it gets displayed as it has been saved - in landscape mode.

Seems to be specific to Samsung devices (you really get to hate Samsung if you program Android apps for a longer time - so many Samsung specific issues you don't have on any other devices).

applehong5013 commented 5 years ago

Thanks you, this will be a nice library, you did it and solve the problem! Cheer!! Thanks you for the effort, appreciate! :D