Skip to content

Correctly rotate and flip image using Exif attributes. - #443

Closed
vanniktech wants to merge 1 commit into
CanHub:mainfrom
vanniktech:fix-orientation
Closed

vanniktech wants to merge 1 commit into
CanHub:mainfrom
vanniktech:fix-orientation

Conversation

@vanniktech

Copy link
Copy Markdown
Contributor

Fixes #439

@vanniktech
vanniktech requested a review from a team as a code owner September 28, 2022 09:42

return when (bitmap) {
null -> RotateBitmapResult(null, degrees, flipHorizontally, flipVertically)
else -> RotateBitmapResult(rotateAndFlipBitmapInt(bitmap, degrees, flipHorizontally, flipVertically), 0, false, false)

Check warning

Code scanning / detekt

Line detected that is longer than the defined maximum line length in the code style.

Line detected that is longer than the defined maximum line length in the code style.
}
} catch (ignored: Exception) {
fun orientateBitmapByExif(bitmap: Bitmap?, context: Context, uri: Uri): RotateBitmapResult {
val exifInterface = context.contentResolver.openInputStream(uri)?.use { ExifInterface(it) }

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now we close every single time just like in #440


return when (bitmap) {
null -> RotateBitmapResult(null, degrees, flipHorizontally, flipVertically)
else -> RotateBitmapResult(rotateAndFlipBitmapInt(bitmap, degrees, flipHorizontally, flipVertically), 0, false, false)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

calling rotateAndFlipBitmapInt is the fix and once we've flipped and rotated we no longer need to rotate / flip hence 0, false, false

@vanniktech
vanniktech marked this pull request as draft September 28, 2022 10:10
@vanniktech

Copy link
Copy Markdown
Contributor Author

Hmm seems like cropping afterwards is broken. Will need to dig a bit further

@vanniktech

Copy link
Copy Markdown
Contributor Author

I've tried but I gave up for now. The moment I change something, another feature breaks. It seems like everything is calibrated to behave on certain not so true data.

For the time being, I'll just copy what's inside rotateAndFlipBitmapInt and do that before passing a bitmap / uri to the library, then it works 🤷

@renzified

Copy link
Copy Markdown

This should already be good to go right?

@vanniktech

Copy link
Copy Markdown
Contributor Author

Unfortuantely not. The cropping logic which crops the image after you've resized / rotated ect relies on the broken image and when fixing it and rotating it, like I've done here the output is just wrong. I haven't had time to look into this yet plus I've got my workaround which seems to be working.

@vanniktech vanniktech closed this by deleting the head repository Oct 19, 2022
@vanniktech

Copy link
Copy Markdown
Contributor Author

I'll get back to it in the future.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] - CropRect has mixed up width / height ⚠️ ⚠️

3 participants