C++导入和重命名/重新保存图像

发布于 2024-09-07 05:32:11 字数 232 浏览 1 评论 0原文

大家好, 我目前是一名即将升入大二的学生(CS专业),今年夏天,我正在尝试自学C++(我的学校代码主要是Java)。 我读过很多关于 C++ 的指南,并了解了 ofstream、保存和编辑 .txt 文件的部分。 现在,我感兴趣的是简单地导入图像(jpeg、位图,不是很重要)并重命名上述图像。 我用谷歌搜索,询问周围但无济于事。 这个过程是否可以在不下载外部库的情况下实现(我使用了 CImg)? 任何有关如何加快我的目标的提示或技巧将不胜感激

Greetings all,
I am currently a rising Sophomore (CS major), and this summer, I'm trying to teach myself C++ (my school codes mainly in Java).
I have read many guides on C++ and gotten to the part with ofstream, saving and editing .txt files.
Now, I am interested in simply importing an image (jpeg, bitmap, not really important) and renaming the aforementioned image.
I have googled, asked around but to no avail.
Is this process possible without the download of external libraries (I dled CImg)?
Any hints or tips on how to expedite my goal would be much appreciated

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

吾性傲以野 2024-09-14 05:32:11

重命名图像通常与重命名任何其他文件大致相同。

如果您想要执行更多操作,还可以更改 IPTC 元数据。这并不需要 JPEG 解码或类似的东西 - 您需要充分了解文件格式才能找到 IPTC 元数据,并充分研究 IPTC 格式才能找到标题字段,但仅此而已。获取 IPTC 元数据的具体方式会有所不同——导航 TIFF(例如)本身就需要相当多的代码。

Renaming an image is typically about the same as renaming any other file.

If you want to do more than that, you can also change the data in the Title field of the IPTC metadata. This does not require JPEG decoding, or anything like that -- you need to know the file format well enough to be able to find the IPTC metadata, and study the IPTC format well enough to find the Title field, but that's about all. Exactly how you'll get to the IPTC metadata will vary -- navigating a TIFF (for one example) takes a fair amount of code all by itself.

听闻余生 2024-09-14 05:32:11

当您说“重命名上述图像”时,您是指更改图像文件中的元数据,还是只是更改文件名?如果您指的是元数据,那么您需要了解文件格式或使用了解文件格式的库。每种类型的图像文件都会有所不同。如果您基本上只想复制文件,则可以将内容从一个文件流流式传输到另一个文件流,或者使用文件系统 API。

std::ifstream infs("input.txt", std::ios::binary);
std::ofstream outfs("output.txt", std::ios::binary);
outfs << insfs.rdbuf();

文件系统 API 的一个示例是 Win32 上的 CopyFile。

When you say "renaming the aforementioned image," do you mean changing metadata in the image file, or just changing the file name? If you are referring to metadata, then you need to either understand the file format or use a library that understands the file format. It's going to be different for each type of image file. If you basically just want to copy a file, you can either stream the contents from one file stream to another, or use a file system API.

std::ifstream infs("input.txt", std::ios::binary);
std::ofstream outfs("output.txt", std::ios::binary);
outfs << insfs.rdbuf();

An example of a file system API is CopyFile on Win32.

拍不死你 2024-09-14 05:32:11

没有库也是可能的 - 你只需要图像规格和“C”,问题是为什么?

Targa 或 bmp 可能是最简单的,它只是一个标头和作为二进制值块的图像数据。
Gif、jpeg 和 png 更复杂 - 数据被压缩

It's possible without libraries - you just need the image specs and 'C', the question is why?

Targa or bmp are probably the easiest, it's just a header and the image data as a binary block of values.
Gif, jpeg and png are more complex - the data is compressed

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文