INNER CODE UNIT · Kotlin
cropLauncher
fumiama/copymanga · app/src/main/java/top/fumiama/copymanga/MainActivity.kt:435
private var cropLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
if (result.resultCode == Activity.RESULT_OK) {
headPic.inputStream().use { fi ->
navhbg.setImageBitmap(BitmapFactory.decodeStream(fi))
}
} else Toast.makeText(this, R.string.err_crop_img, Toast.LENGTH_SHORT).show()
}
private fun cropImageUri() {
val op = UCrop.Options()
val r = navhbg.width.toFloat() / navhbg.height.toFloat()
Log.d("MyMain", "Img info: (${navhbg.width}, ${navhbg.height})")
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
op.setCompressionFormat(Bitmap.CompressFormat.WEBP_LOSSY)
} else {
op.setCompressionFormat(Bitmap.CompressFormat.WEBP)
}
op.setStatusBarColor(resources.getColor(R.color.colorPrimaryDark, theme))