Click here to Skip to main content
14,577,261 members

Excel Pixelating Image Creator

Rate this:
4.58 (13 votes)
Please Sign up or sign in to vote.
4.58 (13 votes)
30 Aug 2017CPOL
Use Excel worksheet's cells as pixels to render real image (for fun and experiment)

Introduction

This little project is to use Excel worksheet's cells as pixels to render real image. It needs .NET 4.5 and local Excel to run. It's coded in C#/Winform/VS 2013.

Background

Basically, the Winform app picks an image from your hard drive, and launches Excel to render the picked image with worksheet cells.

The brief running process is as below:

  1. It picks the image and resamples it into the memory according to your UI inputs (units, columns, etc.).
  2. It launches Excel, makes the spreadsheet cell square-like to simulate a big pixel.
  3. It scans the resampled image in memory either in a linear way or random way (I prefer the random way, the effect is so fun to watch).
  4. It changes cell's background color, one by one (in either linear order or random order)/

(This is what the app looks like.)

Image 1

(It's rendering in Excel in a random way.)

Image 2

(Rendering is done.)

Image 3

Using the Code

The code is very straightforward. It uses VS 2013 (or above), .NET 4.5, C# and Winform.

Make sure you have Office Interop Excel referred properly.

Image 4

Points of Interest

  1. Running Progress Popup

    Originally, I thought I need to do async/await to make a decent progress popup. But you know what, after so many years, this so called "long-run" process handling framework is still hard to use unless you do it on a daily basis. Plus, you have to deal with COM+/Office Interop with this new async/await thing. I have done some experiments, I decide to go with another approach.

    It turns out that, just a regular call can handle it decently. Maybe it's because Office Interop, the system already takes care of this kind of async, worker thread, UI thread switching myth. Frankly, I don't know. But it works.

    Image 5

    You can see the yellow marked code, no fancy async/await stuff, but still does the trick smoothly.

    Image 6

    Obviously the above method still missing a feature: "Cancel".

    To cancel a long run process in the middle, folks, it's not an easy thing to do. It's an advanced topic and case by case (sometimes, you want to rollback, sometimes you just want to kill it...). I'm busy living my own life and this "feature" actually disturbs the main purpose of this little project, so I...

  2. Performance

    If you mess this little app with big size image or super small cells (by change the cell unit size), it will be super slow. Keep in mind that Excel worksheet has limitations (1048576 rows X 16384 cols). But before you even try those numbers, I warned you in my code comments:

    Image 7

  3. Performance Again

    In my experiment, while image rendering, if the "focus" is on Excel, it's slow. But if "focus" is out of Excel, it's faster. Don't ask me why. If you want to figure it out, go nuts, it's all yours. But my humble approach is just to make sure the app is having the focus.

    Can you believe it? This is 2017 and .NET 5.0 era (am I right?) and when you want to do some basic things like "switching focus", you still have to rely on almighty WIN32!

    Image 8

  4. Randomization

    I put the default rendering effect is "Randomization". It's fun to watch. It's well documented in my comments. Just a reminder here as well: it's not "real" random method. It's just good enough to cheat on human eyes.

  5. The Test Image

    I put a photo of "this guy"' as test image for your convenience. It's packaged in the source code zip.

    Image 9

That's about it! Just download the source and play around. I think my comments are also good for you to understand the code.

The souce code solution project can be downloaded here.

I also made a YouTube video to show how it runs. Have fun:

History

  • 30th August, 2017: Initial version

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Geek2Simon
Software Developer
Canada Canada
Just A Geek
Blog: geek2.info


Comments and Discussions

 
GeneralNice project Pin
Mario Z10-Sep-17 1:49
professionalMario Z10-Sep-17 1:49 
GeneralRe: Nice project Pin
Geek2Simon11-Sep-17 12:45
MemberGeek2Simon11-Sep-17 12:45 
QuestionDitto Pin
Doncp31-Aug-17 10:29
MemberDoncp31-Aug-17 10:29 
AnswerRe: Ditto Pin
Geek2Simon31-Aug-17 13:07
MemberGeek2Simon31-Aug-17 13:07 
PraiseMy vote of 5 Pin
Doom For Ever31-Aug-17 8:41
professionalDoom For Ever31-Aug-17 8:41 
GeneralRe: My vote of 5 Pin
Geek2Simon31-Aug-17 13:07
MemberGeek2Simon31-Aug-17 13:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Article
Posted 30 Aug 2017

Stats

9.7K views
352 downloads
6 bookmarked