[英]I want to compress the image
I am not familiar with Kotlin development.我对 Kotlin 开发不熟悉。 I want to compress the image.我想压缩图像。 But don't know how I want to compress getImageFile into a png file.但不知道我想如何将 getImageFile 压缩成一个 png 文件。 How do I compress using the compress method?如何使用 compress 方法进行压缩?
getImageFile.delete()
getImageFile.createNewFile()
val out = FileOutputStream(getImageFile)
contentResolver.openInputStream(imageUri!!)?.copyTo(out)
This is the code that converts the image to a file.这是将图像转换为文件的代码。 How do I do it here我如何在这里做
src.compress(Bitmap.CompressFormat.PNG, 100, FileOutputStream(getImageFile))
I want to replace it using this method.But I get an error in src我想用这种方法替换它。但我在 src 中得到一个错误
The main tasks are the following:主要任务如下:
//open a stream
val stream = ByteArrayOutputStream()
// Compress the bitmap with PNG format and quality e.g. 5%
bitmap.compress(Bitmap.CompressFormat.PNG, 5, stream)
//save it
val byteArray = stream.toByteArray()
bitmap = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.size)
If it doesn't work you should check if your src is okay.如果它不起作用,您应该检查您的 src 是否正常。 You can check out this tutorial -> link , it's the first I found on Google.您可以查看本教程 -> 链接,这是我在 Google 上找到的第一个。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.