简体   繁体   English

mat对象作为字节数组与jpg格式有什么区别?

[英]What is the difference between a mat object as a byte array and the jpg format?

I save the Mat object as byte array: 我将Mat对象保存为byte数组:

public static void save(Mat mat, String name)
{
    File file = new File(path, name);
    int length = (int) (mat.total() * mat.elemSize());
    byte buffer[] = new byte[length];
    mat.get(0, 0, buffer);
    try
    {
        FileUtils.writeByteArrayToFile(file, buffer);
    } catch (IOException e)
    {
        e.printStackTrace();
    }
}

and I save via Imgcodecs.imwrite(); 我通过Imgcodecs.imwrite();保存Imgcodecs.imwrite(); but the file size is very different: the JPG file size is less than 100kb but the byte file size is more than one megabyte. 但是文件大小却大不相同:JPG文件大小小于100kb,但字节文件大小大于1兆字节。

Why is the second file so much bigger? 为什么第二个文件这么大?

The first file is an actual compressed image file. 第一个文件是实际的压缩图像文件。 The second file is simply a byte array, which is not compressed and therefore contains more data and is bigger. 第二个文件只是一个字节数组,未压缩,因此包含更多数据,并且更大。

Check the links below, they explain in further depth what image compression means and the difference between lossy compression and lossless compression. 查看下面的链接,它们更深入地说明了图像压缩的含义以及有损压缩和无损压缩之间的区别。

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

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