Android矩阵Matrix setRectToRect实现标准scaleType中心缩放centerCrop,Kotlin
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
tools:context=".MainActivity">
<ImageView
android:id="@+id/image1"
android:layout_width="400px"
android:layout_height="wrap_content"
android:scaleType="fitStart"
android:src="@mipmap/p4m" />
<ImageView
android:id="@+id/image2"
android:layout_width="300px"
android:layout_height="300px"
android:src="@mipmap/p4m"
android:scaleType="centerCrop" />
<ImageView
android:id="@+id/image3"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.graphics.Canvas
import android.graphics.Matrix
import android.graphics.RectF
import android.os.Bundle
import android.util.Log
import android.widget.ImageView
import androidx.appcompat.app.AppCompatActivity
import kotlin.math.min
class ImageActivity : AppCompatActivity() {
companion object {
const val SIZE = 300
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_image)
val image1 = findViewById<ImageView>(R.id.image1)
image1.setImageResource(R.mipmap.p4m)
val image3 = findViewById<ImageView>(R.id.image3)
val bmp = BitmapFactory.decodeResource(resources, R.mipmap.p4m)
image3.setImageBitmap(scale(bmp))
}
private fun scale(srcBmp: Bitmap): Bitmap {
val t = System.currentTimeMillis()
val bmp = Bitmap.createBitmap(SIZE, SIZE, Bitmap.Config.ARGB_8888)
val c = Canvas(bmp)
val width: Int = srcBmp.width
val height: Int = srcBmp.height
val bmpCenterX: Float = width / 2f
val bmpCenterY: Float = height / 2f
val minVal = min(width, height)
val srcRectF = RectF(
bmpCenterX - minVal / 2,
bmpCenterY - minVal / 2,
bmpCenterX + minVal / 2,
bmpCenterY + minVal / 2
)
val dstRectF = RectF(0f, 0f, SIZE.toFloat(), SIZE.toFloat())
val matrix = Matrix()
//把bitmap中心区域的那一块放到目标的dstRectF里面。
matrix.setRectToRect(srcRectF, dstRectF, Matrix.ScaleToFit.CENTER)
c.drawBitmap(srcBmp, matrix, null)
Log.d("耗时", "scale=${System.currentTimeMillis() - t}")
return bmp
}
}
Android简单把高大于宽或宽大于高的图从中心截成正方形,Kotlin-CSDN博客文章浏览阅读742次,点赞9次,收藏12次。Android BitmapFactory.decodeResource读取原始图片装载成原始宽高Bitmap,Kotlin_bitmapfactory解码宽高-CSDN博客。Android矩阵setRectToRect裁剪Bitmap原图Matrix放大,mapRect标记中心区域,Kotlin-CSDN博客。实现的是把原图中心区域的一片小图挖取出来放大放到下面的ImageView里面,现在不再固定中心位置,而是以手指在上图的触点位置为中心位置,挖取一片区域图放大,然后放到下面的ImageView里面。https://zhangphil.blog.csdn.net/article/details/139181062
Android用setRectToRect实现Bitmap基于Matrix矩阵scale缩放RectF动画,Kotlin(二)_android bitmap 动画-CSDN博客文章浏览阅读772次,点赞4次,收藏5次。【代码】Android用setRectToRect实现Bitmap基于Matrix矩阵scale缩放RectF动画,Kotlin(二)_android bitmap 动画https://blog.csdn.net/zhangphil/article/details/135992780Android矩阵Matrix变换setRectToRect,Kotlin_android rect 矩阵-CSDN博客文章浏览阅读711次,点赞7次,收藏8次。Android拼接合并图片生成长图代码实现合并两张图片,以第一张图片的宽度为标准,如果被合并的第二张图片宽度和第一张不同,那么就以第一张图片的宽度为准线,对第二张图片进行缩放。Android拼接合并图片生成长图代码实现合并两张图片,以第一张图片的宽度为标准,如果被合并的第二张图片宽度和第一张不同,那么就以第一张图片的宽度为准线,对第二张图片进行缩放。基础上,把剪切的区域从矩形Rect变为圆形的Path,当手指在上面的ImageView移动时候,下面同等大小对应的坐标区域显示“剪切”出来的圆形图。_android rect 矩阵
https://blog.csdn.net/zhangphil/article/details/135913218