在库中裁剪图像后卡住 Kotlin 库中的裁剪图像

问题描述

不幸的是,我又被卡住了几个小时。 我想将图库中的图像裁剪为特定的纵横比并将其粘贴到 ImageView 中。我还想将图像的路径保留在字符串中。 问题是我的画廊的 ImageCropper 会在我裁剪图像后立即挂起。我永远卡在这个屏幕上。因此裁剪后的图像不会传回我的应用。

enter image description here

这里是代码的一些重要部分:

private fun pickImageFromGallery() {
    val intent = Intent(Intent.ACTION_PICK)
    intent.type = "image/*"
    intent.putExtra("crop","true");
    intent.putExtra("aspectX",3);
    intent.putExtra("aspectY",2);
    intent.putExtra("outputX",640);
    intent.putExtra("outputY",426);
    intent.putExtra("noFaceDetection",true);
    intent.putExtra("outputFormat",Bitmap.CompressFormat.JPEG.toString())
    intent.putExtra("return-data",true);
    startActivityForResult(intent,IMAGE_PICK_CODE)
}

override fun onActivityResult(requestCode: Int,resultCode: Int,data: Intent?) {
    super.onActivityResult(requestCode,resultCode,data)

    if (resultCode == Activity.RESULT_OK && requestCode == IMAGE_PICK_CODE) {
        dev_img.setImageURI(data?.data)
    } else {
        Toast.makeText(
            applicationContext,"Vorgang abgebrochen.",Toast.LENGTH_SHORT
        ).show()
    }
}

如果没有 intent.putExtra 命令,图像会直接从图库中提取到应用程序中。不幸的是然后没有裁剪。 我不想在我的应用程序中使用外部库,所以我几乎没有在互联网上找到任何解决方案。我希望有人认识到我的问题并可以帮助我纠正它。谢谢。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...