mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-23 04:57:59 +01:00
use the GlideDecoder at SubsamplingScaleImageView
This commit is contained in:
parent
467f603ba1
commit
f4d9ab0ff5
2 changed files with 15 additions and 0 deletions
|
@ -33,6 +33,7 @@ import com.simplemobiletools.gallery.extensions.config
|
|||
import com.simplemobiletools.gallery.extensions.getFileSignature
|
||||
import com.simplemobiletools.gallery.extensions.getRealPathFromURI
|
||||
import com.simplemobiletools.gallery.extensions.portrait
|
||||
import com.simplemobiletools.gallery.helpers.GlideDecoder
|
||||
import com.simplemobiletools.gallery.helpers.GlideRotateTransformation
|
||||
import com.simplemobiletools.gallery.helpers.MEDIUM
|
||||
import com.simplemobiletools.gallery.models.Medium
|
||||
|
@ -199,6 +200,7 @@ class PhotoFragment : ViewPagerFragment() {
|
|||
private fun addZoomableView() {
|
||||
if ((medium.isImage()) && isFragmentVisible && view.subsampling_view.visibility == View.GONE) {
|
||||
view.subsampling_view.apply {
|
||||
setBitmapDecoderClass(GlideDecoder::class.java)
|
||||
maxScale = 10f
|
||||
beVisible()
|
||||
setImage(ImageSource.uri(medium.path))
|
||||
|
|
|
@ -5,6 +5,7 @@ import android.graphics.Bitmap
|
|||
import android.graphics.Canvas
|
||||
import android.graphics.drawable.BitmapDrawable
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.media.ExifInterface
|
||||
import android.net.Uri
|
||||
import com.bumptech.glide.Glide
|
||||
import com.bumptech.glide.load.DecodeFormat
|
||||
|
@ -14,9 +15,13 @@ import com.davemorrissey.labs.subscaleview.decoder.ImageDecoder
|
|||
|
||||
class GlideDecoder : ImageDecoder {
|
||||
override fun decode(context: Context, uri: Uri): Bitmap {
|
||||
val exif = android.media.ExifInterface(uri.path)
|
||||
val orientation = exif.getAttributeInt(android.media.ExifInterface.TAG_ORIENTATION, android.media.ExifInterface.ORIENTATION_NORMAL)
|
||||
|
||||
val options = RequestOptions()
|
||||
.format(DecodeFormat.PREFER_ARGB_8888)
|
||||
.diskCacheStrategy(DiskCacheStrategy.NONE)
|
||||
.transform(GlideRotateTransformation(context, getRotationDegrees(orientation)))
|
||||
|
||||
val drawable = Glide.with(context)
|
||||
.load(uri)
|
||||
|
@ -45,4 +50,12 @@ class GlideDecoder : ImageDecoder {
|
|||
drawable.draw(canvas)
|
||||
return bitmap
|
||||
}
|
||||
|
||||
// rotating backwards intentionally, as SubsamplingScaleImageView will rotate it properly at displaying
|
||||
private fun getRotationDegrees(orientation: Int) = when (orientation) {
|
||||
ExifInterface.ORIENTATION_ROTATE_270 -> 90f
|
||||
ExifInterface.ORIENTATION_ROTATE_180 -> 180f
|
||||
ExifInterface.ORIENTATION_ROTATE_90 -> 270f
|
||||
else -> 0f
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue