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.
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 resample it into the memory according to your UI inputs (units, columns etc.)
(2) It launches Excel, make 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 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)
(It's rendering in Excel in a random way)
(Rendering is done)
Using the code
The code is very strait forward. It uses VS 2013 (or above), .NET 4.5, C# and winform.
Make sure you have Office Interop Excel refered properly
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 still hard to use unless you do it on daily basis. plus, you have to deal with COM+/Office Interop with this new async/await thing. 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 swiching myth. Frankly, I don't know. But it works.
You can see the yellow marked code, no fancy async/await stuff, but still does the trick smoothly.
Obviously the above method still missing a feature: "Cancel".
To cancel a long run process in middle, folks, it's not an easy thing to do. It's advanced topic and case by case (sometimes you want to rollback, sometimes you just want to kill it...). I'm busy on living my own life and this "feature" actually disturbs the main purpose of this little project, so I...
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:
(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!
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.
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 is here:
I also made a YouTube video to show how it runs. Have fun: