-
hidden picture
I want to call a bmp from a file and load onto a form. Then paint it with one solid color so it can be revealed as you "draw" on it. This is for my 4 yr old who has a similar program but I thought it'd be cool if she could uncover pictures of her favorite characters and family members.
I can't figure out how to do this. Could anyone help. I can't pay any money but I can tell you this will really make a little girl smile.
any help is appreciated!
JoeyO
-
1 Attachment(s)
Take a look on this...
I hope it helps.
Arie.
-
Can't give any code, but I think you could do this:
Load a picImg(index) everytime you load a BMP
Load a picBlk(index) everytime you load a BMP
MAKE SURE picImg(..) and picBlk(..) have ScaleMode = 3
When you click on picBlk, (mousedown), set a Boolean (draw) to true, and bitblt (http://vbden.tripod.com/articles/invmask.htm) a the 5x5 area on the picImg that is where they clicked on picBlk. (centred at the mouse, get X and Y vals) In mousemove, if draw = true then you could do the same bitblt. On mouseup you could set draw to false.
This should achieve the desired effect.
-
I wrote a simple little program that covers most of what you want.
First of all you need a module for global varialbes and function definitions. In that module put the following code
[code]
'General declarations
Public Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long
Public Declare Function CreateCompatibleBitmap Lib "gdi32" (ByVal hdc As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long
Public Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
Public Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Public Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
Public Declare Function SetPixelV Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal crColor As Long) As Long
Public Declare Function CreatePen Lib "gdi32" (ByVal nPenStyle As Long, ByVal nWidth As Long, ByVal crColor As Long) As Long
Public Declare Function MoveToEx Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, lpPoint As POINTAPI) As Long
Public Declare Function LineTo Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
Public Type POINTAPI
x As Long
y As Long
End Type
'Image Painting Functions
Public Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
Public Base_DC As Long
Public Layer1_DC As Long
Public Layer2_DC As Long
[code]
Next we create two functioins. LoadBitmap will load a bitmap to memory and intiallize the DC's. UpdatePicture updates the picturebox you are drawing in. I put both of these in the module.
Code:
Public Sub LoadBitmap(Filename As String, hdc As Long, nWidth As Long, nHeight As Long)
Dim temp As IPictureDisp
Dim temp2 As Long
'Create Device Context's
Base_DC = CreateCompatibleDC(0)
Layer1_DC = CreateCompatibleDC(0)
Layer2_DC = CreateCompatibleDC(0)
'load base image to memory
Set temp = LoadPicture(Filename)
SelectObject Base_DC, temp
DeleteObject temp
'load mask overlays
temp2 = CreateCompatibleBitmap(Base_DC, nWidth, nHeight)
SelectObject Layer1_DC, temp2
DeleteObject temp2
temp2 = CreateCompatibleBitmap(Base_DC, nWidth, nHeight)
SelectObject Layer2_DC, temp2
DeleteObject temp2
'set pen colors
SelectObject Layer2_DC, CreatePen(0, 30, vbWhite)
SelectObject Layer1_DC, CreatePen(0, 30, vbBlack)
End Sub
Public Sub UpdatePicture(Pic As PictureBox)
BitBlt Pic.hdc, 0, 0, Pic.Width, Pic.Height, Base_DC, 0, 0, vbSrcCopy
BitBlt Pic.hdc, 0, 0, Pic.Width, Pic.Height, Layer2_DC, 0, 0, vbSrcAnd
BitBlt Pic.hdc, 0, 0, Pic.Width, Pic.Height, Layer1_DC, 0, 0, vbSrcPaint
Pic.Refresh
End Sub
Ok, now that the module is complete we move onto the form. Add a picutre box that will contain the drawing.
Add a command button to reset the image
In the command button click event place this code
Code:
DeleteObject Base_DC
DeleteObject Layer1_DC
DeleteObject Layer2_DC
DeleteDC Layer1_DC
DeleteDC Layer2_DC
DeleteDC Base_DC
LoadBitmap "D:\TEST.BMP", Picture1.hdc, Picture1.Width, Picture1.Height
UpdatePicture Picture1
In the picturebox place this code under mouse_down
Code:
Dim temp As POINTAPI
If Button = 1 Then
MoveToEx Layer1_DC, x, y, temp
MoveToEx Layer2_DC, x, y, temp
UpdatePicture Picture1
End If
and in the mousemove event
Code:
If Button = 1 Then
LineTo Layer1_DC, x, y
LineTo Layer2_DC, x, y
UpdatePicture Picture1
End If
finally you must clear the memory DC's. In the Form1 QuerryUnload event place this
Code:
DeleteObject Base_DC
DeleteObject Layer1_DC
DeleteObject Layer2_DC
DeleteDC Layer1_DC
DeleteDC Layer2_DC
DeleteDC Base_DC
and that does it. when you run the program click and drag on
the picture box to reaveal the hidden image. If you want you
could start with a top image by loading two identical images into
Layer1_DC and Layer2_DC like you did for the Base_DC. Note
that there is no automatic sizing int he code above, so you might
have to write that yourself.