Mask Creator in VB6
Author : Sumit Gupta
Once you look for making a Graphics Rich Application you need to get such images that has transparent background. We get most of the Free Icons and Images to have Transparent background but what if you want you to put that "Special Image" that doesn't have any transparent background, now the other problem is that you are a programmer and doesn't know much about the graphics softwares. So, we need to do it Programmers way that is doing some calculation here and there and we make our stuff from within Visual Studio environment.
So, this effort for making Transparent Background through MASK is the only solution I can think of. For Masking we need a piece of code that can mask the require Image into MASK image so that we can do what ever we want. So lets program MASK CREATOR to do the job for us.
So the purpose of the software is to make a new bitmap with the given picture which can be used as the mask of it.
What is MASK ?
Well, in simple word MASK is the picture in which only shadow is taken form a actual picture like in the given box below if I want to create a mask

It will look something like this

How to make a mask of the picture?
The basic idea behind the Mask image is that change the given color (area you want to make transparent, BLACK in our case) in the picture to the white color and other area to the black.
Why make 'Mask' picture?
For this you need to see Transparent Background and Other imaging concept. Will be added soon here.
How I did it?
Now start reading the picture, by reading its pixels. Now change the value of this pixel.
Visual Basic 6.0 Code for doing this is
CreateMask() is a simple function that change the ImagePixels (array of the Picture image) elements depending upon the Color they have. 'Forecolor' is the color we want to change to make transparent image (in our game or other graphic display this article/tutorial will not tell you how to do that).
Now to make this ImagePixel array I simply use the GetPixel API function of the Windows and read the image from the Picture box pixel by pixel and copy the value (basically the color value of the image) in my 2D Array in same order.
Now to display the Image in our required place like on form or picture box simply set its pixel one by one in same order and that is it.
Just this much is needed to be done and your application is complete. Though I have added few other option like saving the mask (other wise what the use of making the Mask image).
The Function used in this from Windows API is just
Public Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long) As Long
Public Declare Function SetPixel Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long, ByVal crColor As Long) As Long