Results 1 to 4 of 4

Thread: hidden picture

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 1999
    Location
    ma,usa
    Posts
    485

    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

  2. #2
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Israel
    Posts
    636
    Take a look on this...
    I hope it helps.

    Arie.
    Attached Files Attached Files

  3. #3
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    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.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  4. #4
    Lively Member
    Join Date
    May 2000
    Posts
    84
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width