如何使用JPEG文件 [英] How to work with JPEG file

查看:122
本文介绍了如何使用JPEG文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

想要想要编写一个程序,可以旋转图像,减去,添加两个图像,但我不知道如何读写JPEG文件,我不知道格式JPEG文件。有人可以帮帮我吗?

解决方案

你不需要知道 JPEG 文件的格式来进行操作他们。例如,您可以使用 GDI + 加载(并操纵)它们(例如,参见旋转,反射和歪斜图像 [ ^ ])。


如果GDI +不是你的选择,那么我建议使用众多库中的一个来转换图像格式。例如这一个:



CxImage [< a href =http://www.codeproject.com/Articles/1300/CxImagetarget =_ blanktitle =New Window> ^ ]



这并不意味着你不应该看看JPEG规范,正如Harvey在解决方案2中所建议的那样。这只是意味着JPEG标准对于理解工具并不是一件容易的事情,你最终可能会得到几千行C ++代码。因此,为了获得更快的结果,您可能需要使用一个好的库。



关于旋转的一个词。您可以通过将JPEG图像转换为位图来旋转它,然后旋转它(这非常简单),然后将其重新编码为JPEG。然而,这个过程并非绝对无损,因为JPEG是一种有损压缩方法。然而,只需通过操纵内部数据结构,就可以旋转JPEG图像而不将其转换为位图。一些库支持JPEG旋转损失。只需谷歌jpegtran。


可以找到JPEG的文件格式以及如何构建/操作它此处 [ ^ ]。

I wanna want to write a program which can rotate image, substract, add two image but I don't know how to read and write to JPEG file, and I do not know the format of JPEG file. Can someone help me?

解决方案

You don't need to know the format of the JPEG files for manipulating them. You may, for instance load (and manipulate) them using GDI+ (see, for instance "Rotating, Reflecting, and Skewing Images"[^]).


If GDI+ is not an option for you, then I would recommend to use one of the many libraries for converting image formats. For example this one:

CxImage[^]

That doesn't mean you should not have a look at the JPEG specification, as Harvey suggested in Solution 2. It just means that the JPEG standard is not trivial to understand implement and you might end up with a couple thousand line of C++ code. So for faster results you might want to use a good library.

A word about rotation. You can rotate a JPEG image by converting it into a bitmap, then rotate it (which is quite easy) and then re-encode it as a JPEG. This process is however not absolutely lossless, because JPEG is a lossy compression method. There is however a way of rotating a JPEG image without converting it into a bitmap, just by manipulating the internal data structures. Some libraries support lossles JPEG rotation. Just google for "jpegtran".


The file format for JPEG and how to build/manipulate one can be found here[^].


这篇关于如何使用JPEG文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆