英文:
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)
}
专注分享java语言的经验与见解,让所有开发者获益!
评论