Add "Rotate wide pages to fit" setting for paged reader
Originally authored in #7983 Co-authored-by: timothyng-164 <timothyng-164@users.noreply.github.com> (cherry picked from commit 953720472fe64ef488ecae7ae7fea453b8c7c68b) # Conflicts: # app/src/main/java/eu/kanade/tachiyomi/ui/reader/setting/ReaderReadingModeSettings.kt # app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerConfig.kt # app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerPageHolder.kt # app/src/main/res/layout/reader_pager_settings.xml
This commit is contained in:
@@ -8,6 +8,7 @@ import android.graphics.BitmapFactory
|
||||
import android.graphics.BitmapRegionDecoder
|
||||
import android.graphics.Canvas
|
||||
import android.graphics.Color
|
||||
import android.graphics.Matrix
|
||||
import android.graphics.Rect
|
||||
import android.graphics.drawable.ColorDrawable
|
||||
import android.graphics.drawable.Drawable
|
||||
@@ -152,6 +153,23 @@ object ImageUtil {
|
||||
return ByteArrayInputStream(output.toByteArray())
|
||||
}
|
||||
|
||||
fun rotateImage(imageStream: InputStream, degrees: Float): InputStream {
|
||||
val imageBytes = imageStream.readBytes()
|
||||
|
||||
val imageBitmap = BitmapFactory.decodeByteArray(imageBytes, 0, imageBytes.size)
|
||||
val rotated = rotateBitMap(imageBitmap, degrees)
|
||||
|
||||
val output = ByteArrayOutputStream()
|
||||
rotated.compress(Bitmap.CompressFormat.JPEG, 100, output)
|
||||
|
||||
return ByteArrayInputStream(output.toByteArray())
|
||||
}
|
||||
|
||||
private fun rotateBitMap(bitmap: Bitmap, degrees: Float): Bitmap {
|
||||
val matrix = Matrix().apply { postRotate(degrees) }
|
||||
return Bitmap.createBitmap(bitmap, 0, 0, bitmap.width, bitmap.height, matrix, true)
|
||||
}
|
||||
|
||||
/**
|
||||
* Split the image into left and right parts, then merge them into a
|
||||
* new vertically-aligned image.
|
||||
|
||||
Reference in New Issue
Block a user