canvas에 bitmap 그리기
val originalBitmap = ....
val paint = Paint()
canvas.drawBitmap(originalBitmap, 0f, 0f, paint)
이미지뷰의 drawable이 디바이스에 보이는 사이즈만큼 캔버스 만들어서 뷰 그리기
val sizedBitmap = Bitmap.createBitmap(
getImageBounds((binding.imageView as ImageView)).width().toInt(),
getImageBounds((binding.imageView as ImageView)).height().toInt(),
Bitmap.Config.ARGB_8888
)
val sizedViewCanvas = Canvas(sizedBitmap)
someView.draw(sizedViewCanvas)
fun getImageBounds(imageView: ImageView): RectF {
val bounds = RectF()
val drawable: Drawable? = imageView.drawable
if (drawable != null) {
imageView.imageMatrix.mapRect(bounds, RectF(drawable.bounds))
}
return bounds
}
uri로 이미지 실제 사이즈 가져오기
fun getOriginalImageSize(uri: Uri, context: Context): Pair<Int, Int> {
val options = BitmapFactory.Options()
options.inJustDecodeBounds = true
BitmapFactory.decodeStream(
context.contentResolver.openInputStream(uri),
null,
options
)
val imageHeight = options.outWidth
val imageWidth = options.outHeight
return imageHeight to imageWidth
}
bitmap scaledup
val scaledBitmap = (Bitmap.createScaledBitmap(
textViewBitmap,
500,
500,
true
))
glide 사용 시 - 캐시 사용 안하기 및 사진 로딩 완료 리스너
private fun setImage() {
Glide.with(this)
.load(Uri.parse(uri))
.apply(RequestOptions.skipMemoryCacheOf(true))
.apply(RequestOptions.diskCacheStrategyOf(DiskCacheStrategy.NONE))
.listener(object : RequestListener<Drawable> {
override fun onLoadFailed(
e: GlideException?,
model: Any?,
target: com.bumptech.glide.request.target.Target<Drawable>?,
isFirstResource: Boolean
): Boolean {
return false
}
override fun onResourceReady(
resource: Drawable?,
model: Any?,
target: com.bumptech.glide.request.target.Target<Drawable>?,
dataSource: DataSource?,
isFirstResource: Boolean
): Boolean {
if (resource is BitmapDrawable) {
val bitmap = resource.bitmap
bitmap.byteCount
bitmap.width
bitmap.height
}
return false
}
})
.into(binding.imageView)
}