保存图像而不压缩

huangapple 未分类评论74阅读模式
英文:

Save image without compressing

问题

在我的应用程序中,我使用相机拍摄照片,并将图像存储到内部存储中,但是当我检索存储的图像时,图像的质量变得非常差。是否有任何方法可以在不压缩的情况下存储实际图像?

以下是保存图像的代码部分:

private fun saveImage(bitmap: Bitmap): Uri {
    val wrapper = ContextWrapper(applicationContext)
    var file = wrapper.getDir(IMAGE_DIRECTORY, Context.MODE_PRIVATE)
    file = File(file, "${UUID.randomUUID()}.png")

    try {
        val stream: OutputStream = FileOutputStream(file)
        bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream)
        stream.flush()
        stream.close()
    } catch (e: IOException) {
        e.printStackTrace()
    }

    return Uri.parse(file.absolutePath)
}
英文:

in my app, I am taking photo using the camera and I store the image to internal storage but when I retrieve the stored image, the quality of the image is becomes very poor. is there any way to store the actual image without compressing in?

private fun saveImage(bitmap: Bitmap):Uri{
    val wrapper = ContextWrapper(applicationContext)
    var file = wrapper.getDir(IMAGE_DIRECTORY, Context.MODE_PRIVATE)
    file = File(file, "${UUID.randomUUID()}.png")

    try {

        val stream: OutputStream = FileOutputStream(file)

        bitmap.compress(Bitmap.CompressFormat.PNG,100, stream)
        stream.flush()
        stream.close()
    }catch (e:IOException)
    {
        e.printStackTrace()
    }

    return Uri.parse(file.absolutePath)
}

huangapple
  • 本文由 发表于 2020年8月15日 01:42:01
  • 转载请务必保留本文链接:https://java.coder-hub.com/63417640.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定