开发者

C++ Importing and Renaming/Resaving an Image

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开发者_Python百科 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


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.


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜