winzip icon

Pixel Code Generator

Submitted on: 2/13/2015 3:49:00 PM
By: Option Explicit (from psc cd)  
Level: Beginner
User Rating: By 7 Users
Compatibility: VB 6.0
Views: 3411
     This small, almost totally useless project scans all the pixels in a bitmap stored in a picturebox and generates SetPixelV code to replicate that bitmap. Automatically generates For loop code if enough consecutive pixels are identical to exceed a FORLOOP_THRESHOLD value. Generated code is written to the clipboard for pasting into other projects. Why did I do something so useless, you ask? Well, as many of you know, my hobby at PSC is inflicting usercontrols on you. I prefer things like checkmarks for checkboxes drawn by code as opposed to being stored in imagelists or the like. I don't like dependencies of any kind in controls. So, I draw them using LineTo or SetPixelV. The problem is, I can't even draw a stick figure. I see these nice custom checkmarks in web sites and I couldn't replicate them, so I wrote this. As far as I know checkmarks aren't copyrighted, so hopefully this wouldn't be considered stealing! To use, just use your favorite screen grabber to grab the checkmark or whatever, then MS Paint or whatever to save just the area you want to disk. (You may want to edit colors, or resize, or some such.) Place this bitmap in Picture1 and run the program. Stop the program, and paste the newly generated code into the "Redraw" sub. Run again and click the button under Picture2. Voila! You can tweak the code to take out parts you don't want fairly easily. Only try this with SMALL (32x32 size or less) bitmaps. I tried with larger bitmaps and while the code generates properly, the code for even a smaller photgraph can easily exceed 10,000 lines. A VB procedure can't be larger than 64K. I included a small calculator icon example with the code already loaded into the Redraw routine to get you started. I wouldn't even use this for something the size of the calculator icon but did it just to give you the idea. I'm sure this could be optimized (especially the string concatenation) but it runs great on small bitmaps and I'm not going to endlessly tweak this. Let the flames begin :-)
winzip iconDownload code

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. Afterdownloading it, you will need a program like Winzip to decompress it.Virus note:All files are scanned once-a-day by Planet Source Code for viruses, but new viruses come out every day, so no prevention program can catch 100% of them. For your own safety, please:
  1. Re-scan downloaded files using your personal virus checker before using it.
  2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.
  3. Scan the source code with Minnow's Project Scanner

If you don't have a virus scanner, you can get one at many places on the net

Other 8 submission(s) by this author


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)

Other User Comments

 There are no comments on this submission.

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)

To post feedback, first please login.