pull/298/head
gedoor 4 years ago
parent 019e0fc634
commit 0e10fe1a05
  1. 34
      app/src/main/java/io/legado/app/ui/widget/image/PhotoView.kt

@ -248,22 +248,22 @@ class PhotoView : ImageView {
val img = drawable val img = drawable
val w = width val w = width
val h = height val h = height
val imgw = getDrawableWidth(img) val imgW = getDrawableWidth(img)
val imgh = getDrawableHeight(img) val imgH = getDrawableHeight(img)
mBaseRect[0f, 0f, imgw.toFloat()] = imgh.toFloat() mBaseRect[0f, 0f, imgW.toFloat()] = imgH.toFloat()
// 以图片中心点居中位移 // 以图片中心点居中位移
val tx = (w - imgw) / 2 val tx = (w - imgW) / 2
val ty = (h - imgh) / 2 val ty = (h - imgH) / 2
var sx = 1f var sx = 1f
var sy = 1f var sy = 1f
// 缩放,默认不超过屏幕大小 // 缩放,默认不超过屏幕大小
if (imgw > w) { if (imgW > w) {
sx = w.toFloat() / imgw sx = w.toFloat() / imgW
} }
if (imgh > h) { if (imgH > h) {
sy = h.toFloat() / imgh sy = h.toFloat() / imgH
} }
val scale = if (sx < sy) sx else sy val scale = if (sx < sy) sx else sy
mBaseMatrix.reset() mBaseMatrix.reset()
@ -299,11 +299,11 @@ class PhotoView : ImageView {
if (!hasDrawable) return if (!hasDrawable) return
if (!isKnowSize) return if (!isKnowSize) return
val img = drawable val img = drawable
val imgw = getDrawableWidth(img) val imgW = getDrawableWidth(img)
val imgh = getDrawableHeight(img) val imgH = getDrawableHeight(img)
if (imgw > mWidgetRect.width() || imgh > mWidgetRect.height()) { if (imgW > mWidgetRect.width() || imgH > mWidgetRect.height()) {
val scaleX = imgw / mImgRect.width() val scaleX = imgW / mImgRect.width()
val scaleY = imgh / mImgRect.height() val scaleY = imgH / mImgRect.height()
mScale = if (scaleX > scaleY) scaleX else scaleY mScale = if (scaleX > scaleY) scaleX else scaleY
mAnimMatrix.postScale(mScale, mScale, mScreenCenter.x, mScreenCenter.y) mAnimMatrix.postScale(mScale, mScale, mScreenCenter.x, mScreenCenter.y)
executeTranslate() executeTranslate()
@ -370,9 +370,9 @@ class PhotoView : ImageView {
private fun resetBase() { private fun resetBase() {
val img = drawable val img = drawable
val imgw = getDrawableWidth(img) val imgW = getDrawableWidth(img)
val imgh = getDrawableHeight(img) val imgH = getDrawableHeight(img)
mBaseRect[0f, 0f, imgw.toFloat()] = imgh.toFloat() mBaseRect[0f, 0f, imgW.toFloat()] = imgH.toFloat()
mBaseMatrix.set(mSynthesisMatrix) mBaseMatrix.set(mSynthesisMatrix)
mBaseMatrix.mapRect(mBaseRect) mBaseMatrix.mapRect(mBaseRect)
mHalfBaseRectWidth = mBaseRect.width() / 2 mHalfBaseRectWidth = mBaseRect.width() / 2

Loading…
Cancel
Save