Is there a way to interpret the characters displayed by a text editor when you open an image file with it?
I am doing a research project where I open an image (BMP, JPG, CR2) with a text editor (such as TextEdit on a Mac) and I manipulate the code by copying and pasting code blocks within the body of the document, and removing certain parts, and substituting them for other characters, all random actions. I get certain visual distortions in the image by doing these experiments.
This is an ar开发者_开发技巧t project, however I wanted to know if there is a way to tell what the gibberish characters are representing in terms of particular information, and whether it is easy for any experienced programmer to interpret this information. Is there a "proper" way of displaying image code in order to manipulate it in a more meaningful way? Are there any online resources I can look at?
I am not a programmer by nature, but I am very interested in how code governs visual output.
Well, the "proper way" is called an image viewer...
Maybe a more helpful answer is the following: most of the information in an uncompressed BMP file is triples of numbers which list the red, green, and blue components of the pixels in order (there's also a little bit of information at the top saying how big the file is etc.)
If you'd like to see the numbers in text, you could look into converting the images into PPM format ("portable pixmap"), which has a text-based option that's more human-readable. I'm not sure what you'd get out of it to be honest though. See http://en.wikipedia.org/wiki/Netpbm_format
The reason this looks like gibberish in a text editor is that basic text is stored as 7-bit ASCII, which stores a number between 0 and 127 for each basic letter, number or punctuation character. Bytes can hold numbers between 0 and 255, so lots of the bytes in the file that you see don't get mapped to "normal characters". Now, there are many different ways to interpret larger numbers like this (if you're interested look up Unicode), but whatever happens, you're likely to get mangled nonsense as you see.
Images in JPG format (or PNGs etc.) have a much cleverer format, which allows more efficient storage of the information. But there isn't such a direct link between bytes and pixels, so it's unclear what exactly you'd want to see in your description above.
精彩评论