Android ImageDecoder把瘦高/扁平大图相当于fitCenter模式decode成目的小尺寸Bitmap,Kotlin
- val sz = Size(MainActivity.SIZE, MainActivity.SIZE)
- val src = ImageDecoder.createSource(mContext?.contentResolver!!, uri)
- val bitmap = ImageDecoder.decodeBitmap(src, object : ImageDecoder.OnHeaderDecodedListener {
- override fun onHeaderDecoded(decoder: ImageDecoder, info: ImageDecoder.ImageInfo, source: ImageDecoder.Source) {
- decoder.allocator = ImageDecoder.ALLOCATOR_SOFTWARE
- //最小边。
- val minEdge = Math.min(info.size.width, info.size.height)
- //竖长或扁平的图,按照原图最小的边,把原图缩小到目标宽高的采样值。
- val sample = if (minEdge == info.size.width) {
- info.size.width / sz.width
- } else {
- info.size.height / sz.height
- }
- //如果原始图/视频尺寸比目标的尺寸大。
- if (sample > 1) {
- val cx = (info.size.width) / 2
- val cy = (info.size.height) / 2
- val rect = Rect(cx - minEdge / 2, cy - minEdge / 2, cx + minEdge / 2, cy + minEdge / 2)
- decoder.crop = rect
- }
- }
- })
复制代码
Android矩阵Matrix setRectToRect实现尺度scaleType中央缩放centerCrop,Kotlin_安卓 rect matrix-CSDN博客文章欣赏阅读696次,点赞21次,收藏18次。Android拼接归并图片生发展图代码实现归并两张图片,以第一张图片的宽度为尺度,假如被归并的第二张图片宽度和第一张差别,那么就以第一张图片的宽度为准线,对第二张图片举行缩放。Android拼接归并图片生发展图代码实现归并两张图片,以第一张图片的宽度为尺度,假如被归并的第二张图片宽度和第一张差别,那么就以第一张图片的宽度为准线,对第二张图片举行缩放。底子上,把剪切的地域从矩形Rect变为圆形的Path,当手指在上面的ImageView移动时间,下面划一巨细对应的坐标地域体现“剪切”出来的圆形图。_安卓 rect matrixhttps://blog.csdn.net/zhangphil/article/details/139753381
|