简体   繁体   English

Android如何在不损失质量的情况下将png格式的图像转换为jpeg格式

[英]Android how to convert a png format image to jpeg format without loss quality

I develop an app which involves a step of uploading image to server.But the server only support jpeg format image,so I have to convert the png format images picked or captured by users on client side.So I use the follow codes do this image format transformation: 我开发了一个应用程序,其中涉及到将图像上传到服务器的步骤。但是服务器仅支持jpeg格式的图像,因此我必须转换用户在客户端选择或捕获的png格式的图像。因此,我使用以下代码来处理此图像格式转换:

bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outputStream);

but some images will loss quality,compared to png format and the eyes can see the loss.Does this method has some bugs?Are there some good methods to do png to jpeg transformation without loss quality in Android? 但是有些图像会损失质量,与png格式相比,眼睛会看到损失。此方法是否存在一些错误?在Android中是否有一些好的方法可以将png转换为jpeg,而不会损失质量?

JPEG is a lossy compression format, it will have data loss. JPEG是一种有损压缩格式,它将丢失数据。 See the post here: 在这里查看帖子:

Saving JPEG files in Android with no loss of pixel information 在Android中保存JPEG文件而不会丢失像素信息

The idea behind "compression" is to reduce the file size, but there is always a tradeoff. “压缩”背后的想法是减小文件大小,但是总要权衡取舍。 You may try increasing the size of the PNG file and then doing "compression" - but then you may need to scale it back down and you are back where you started. 您可以尝试增加PNG文件的大小,然后执行“压缩”-但随后可能需要将其按比例缩小,然后回到开始的位置。

NOTE: PNG is not "lossy" and is "compressed" compared to some other formats, eg Bitmap. 注意:与其他某些格式(例如位图)相比,PNG并非“有损”,而是“压缩”的。 I originally posted with the assumption that compression = lossy, but some formats are considered "compressed" simply because they require less storage and without loss. 我最初发布时假设压缩=有损,但是某些格式被认为是“压缩”的,仅仅是因为它们需要更少的存储空间且没有损失。 For example, Zip is a file format that will change file data organization to store them with less space and without loss. 例如,Zip是一种文件格式,它将更改文件数据的组织方式,以更少的空间且不会丢失而存储它们。

This is a different type of compression from what JPEG does, which alters the information in order to "compress" the file, and store it in a smaller file. 这是与JPEG不同的压缩类型,后者更改信息以“压缩”文件并将其存储在较小的文件中。 Compression of this type is fundamentally different. 这种类型的压缩从根本上是不同的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM