Visual Basic CAN do fast graphics – I promise
To my fellow VB 6.0 users:
In my experience, many VB programmers seem to believe that fast graphics programming is impossible in VB. Most complain that PSet and Point (or GetPixel and SetPixel) just aren’t fast enough for their needs, and they feel like they have to switch to an alternate language for any serious graphics-related coding.
This is most definitely not the case, and I hope by the end of these tutorials to have you feeling quite differently.
Using some creativity and efficient coding, you can use VB6 to do almost anything that C++, java, DirectX or OpenGL does – and almost always as fast (and in some cases faster!). The code for DIB sections, the ultimate end of these tutorials, is not well-documented anywhere else on the net, so I have set out to clearly explain how extremely fast graphics-related code can be used inside Visual Basic without a lot of extra work or overly-cryptic API calls.
Also, unlike other programming tutorials, this series of articles will explain not only how to do fast graphics but how fast graphics work. You will first learn about pure VB routines for graphics processing; next comes the basic API routines of GetPixel and SetPixel/V; third comes the more advanced GetBitmapBits, SetBitmapBits, and DIB sections; the last tutorial will cover additional optimizations for the real speed demons out there. By the end of this series of tutorials you will be able to effectively write any graphics application you can dream up using nothing but VB6 and the Windows API.
But before we jump into the code, it’s probably good to clarify a little bit about graphics programming in general.
General Graphics Programming Stuff
Graphics programming (hereafter referred to as GP) is, in my opinion, the most far-reaching aspect of programming. Every Windows, Linux, and Mac program that has been written in the last twenty years has utilized graphics in some way. Because of the popularity of GUI-based operating systems, every programmer has been forced to learn at least the fundamentals of GP, because any program they write must include little picture boxes, have nice buttons and toolbars, load with a pretty splash screen, etc.
Now it’s true that some programs don’t use many graphics routines – but every program you own uses some graphics. Next time you turn on your computer, start thinking about all of the GP involved in simple, everyday routines, like clicking on your start bar, the animated folder that appears when you copy a file, that progress bar at the bottom of a window. You’ll quickly be amazed at how many GP techniques are utilized within every program you run.
As you can imagine, a lot could be said about graphics programming. I do not intend to talk about EVERYTHING graphics related, so here’s the part of GP that this set of tutorials will cover: per-pixel image interface routines. Basically, we’re going to discuss how to get a picture’s pixel information, how to transfer it into a data structure we can use (arrays), and how to put those pixels back onto the screen once we’re done with them. We’ll go from the easiest and slowest ways to the fastest and most advanced ways available to you, the common VB6 programmer.
What this tutorial will not cover is how to do specific image editing routines (please refer to the numerous source code examples on the internet for that), how to write graphics-based dlls or ocxs, or how to use DirectX. There are resources for each of these if you are interested; my goal is simply to outline the standard Windows API methods for per-pixel image interfacing.
Are you excited? You should be! On to the tutorials!
CONTINUE TO “PURE VB PIXEL ROUTINES”
Disclaimer and Legal Stuff
Copyright © 2005-2009 Tanner Helland. This article may not be reproduced in any form (printed or electronic) without prior written consent from the author. This document may, however, be freely hyperlinked without permission from the author.
All programming source code associated with these articles is provided “as is”. In no event shall the author or any of his affiliates be liable for any consequential, special, incidental or indirect damages of any kind arising out of the delivery, performance or use of this source code, to the maximum extent permitted by applicable law. While this code has been developed with great care, it is not possible to warrant that it is error free. This source code is not designed or intended to be used in any activity that may cause personal injury, death or any other severe damage or loss.
Related articles:


very great tutoriaL
do u have tutor about image compressing using neural network?