Home > My Thoughts, Programming > File To Image Converter

File To Image Converter

When I run out of programming ideas I program some weird & sometimes useless stuff just for fun :D.

This program converts a file into a bitmap and then saves it as a Png\Bmp image, the file then can be retrieved (along with its name) from the image.


A 7MB file converted into an image

The idea is that each pixel in the bit map contains 3 components ( Red, Green, Blue), each one of them can have one of 256 values (one byte), so each pixel can hold three or four bytes from the file.

First the program concatenates these bytes:
File Length (6 bytes) + File Name (Terminated by a 0 byte) + File Contents
After the stream is ready its saved into a bitmap using RGB channels if the image format is Bmp, or into ARGB channels if the image format is Png :).

Both Png,Bmp images are saved 32 bits per pixel, I tried saving a Bmp with 24 bits per pixel but it didn’t work. I didn’t do much googling anyway.

Since large files can produce a large image I had to create a user control that consists of an image and two scroll bars, & I wouldn’t recommend dealing with files larger than 100 MB (Unless you have both RAM & time πŸ™‚).

Here’s the executable & source code ( just for fun πŸ˜€ ) :

File To Image Executable ( 10 KB ) .NET Framework 4 Client Profile

File To Image Source Code ( 20 KB ) Visual Studio 2010

What to do:

Open a file to encrypt using the button “Open File To Encrypt“, wait until the operation is done then save the result as an image using the button “Save Encrypted File As Image“.

Now you have the file saved as a normal image, you can open it using any image viewer.

To retrieve the file simply click the button “Open Image To Decode” and select the image you saved earlier , wait until the operation is done, if everything went okay a save file dialog will ask you where you want to save the file :D, The file should be identical to the one you encrypted before :D.

Categories: My Thoughts, Programming
  1. No comments yet.
  1. No trackbacks yet.

What do you think?

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: