I'm trying to make a C++ console app that can convert binary(mp3) files to images. How can I read every binary character in the file, convert to hex, and then save it as an image. Here is what I want but in C++
Asked
Active
Viewed 5,571 times
2
-
Do you want us to convert that code for you? I hope you tried yourself. Tell us where the problems are with your approach. – jwueller Dec 06 '10 at 12:51
-
Maybe not convert it, but just give me a few examples of how to start. Like how to read the binary and convert to hex + how to save that in bitmap. Im a total beginner in C++ :S – nebkat Dec 06 '10 at 12:52
-
How on earth an mp3 can be converted to an image? – Jaywalker Dec 06 '10 at 12:56
-
1There is no such thing as 'converting to hex'. You can convert a value into **text that represents** the number in base 16, but bytes simply represent numbers, and **numbers have no inherent base**. "Ten" is "ten" no matter whether you work in hex, decimal or binary. – Karl Knechtel Dec 06 '10 at 12:56
-
@Jaywalker data does not have an inherent type. Type is an interpretation we impose upon data. The linked code effectively re-interprets the data of the input file as if it were raw bitmap data, and then uses a library to save that bitmap data in its .png representation. – Karl Knechtel Dec 06 '10 at 12:58
-
@Jaywalker, to extend on what Karl said, this means you can place a program on a web site as an image. Providing the software that is showing that web page recognises that an image is, in fact, a program (say by some special byte sequence or pattern), it can download the image and convert it to something it can execute/install. – Moo-Juice Dec 06 '10 at 13:01
-
Perhaps learning C++ first would be a good help :) – Tony The Lion Dec 06 '10 at 13:35
-
@Karl Knechtel, I know you can convert them to hex, but here is an example pic: http://img228.imageshack.us/img228/1339/hexbin.png . I want to take in the ÿ and output ff. – nebkat Dec 06 '10 at 14:02
-
@Karl Knechel: Didn't they try that defence in the early days of mp3-sharing when they were getting sued for copyright infringement? i.e. that it wasn't really music, just a stream of 1s and 0s. I think they tried that one with porn image distribution too. I just hope what they are trying to do isn't part of a disguise of illegal file-sharing. – CashCow Dec 06 '10 at 14:30
-
@CashCow, not my responsibility. :) @Neb, the ÿ and the ff **are the same thing**. They are two **on-screen representations** of the same byte in the file. – Karl Knechtel Dec 06 '10 at 18:24
2 Answers
1
You might find this tutorial helpful:
http://www.cplusplus.com/doc/tutorial/files/ (Scroll down to the section binary files)
Also, let me share my standard recommended links for people asking for aid on basic c++:
C++ Language Reference (including STL)
ANSI C Language reference for all those pesky C stuff that C++ keeps using

sum1stolemyname
- 4,506
- 3
- 26
- 44
0
- Create an image with an area big enough to fit the data in.
- For each byte in the source file, set a pixel. You could do this a number of ways - monochrome, or take bytes in threes and write them as red, green and blue for a 24-bit colour image.
- Save the image to disk, e.g. in PNG format using libpng.
If you want a more specific answer, you'll need to ask a more specific question.

AshleysBrain
- 22,335
- 15
- 88
- 124