Results 1 to 8 of 8

Thread: BitBlt once to memory?

Hybrid View

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2001
    Posts
    421

    BitBlt once to memory?

    I'm sure it's not possible from what I know, but here goes...

    I know how to blit a mask, then blit a graphic onto it to make it transparent, but how can I do this and store it in memory, retaining the transparency? I'm trying to just blit it once with transparency, then just pull it from memory whenever I need it. Possible? If so, can you give me a little push into the right direction? Thanks.
    [vbcode]
    ' comment
    Rem remark
    [/vbcode]

  2. #2
    Fanatic Member petrus's Avatar
    Join Date
    May 2002
    Location
    pBytes[sizeof(pBytes)/2]
    Posts
    553
    You can't, because the memory must have a value everywhere.
    ICQ: 128716725

  3. #3
    Addicted Member drewski's Avatar
    Join Date
    Feb 2000
    Location
    WA
    Posts
    242

    This is only an idea ...

    You might be able to do something similar to this. I'm assuming you're using normal Bitblt to do your transparent blts. Well, this involves two separate blts if I remember correctly. I can't remember the operator names (vbscrpaint/vbsrccopy) but couldn't you do one and put that in memory and then grab it when you need to do the second blt later? That way you can do one blt a head of time and save yourself from blting twice, who knows how many times, later?

    This might not work but hey, its an idea.

  4. #4
    Lively Member
    Join Date
    Mar 2002
    Posts
    110
    this will create your image and load it into a back buffer the size of your image, just use BitBlt to blit the back buffer (hdcBuffer is the variable name) to anywhere on the form. to blit to a picture box, change the form1.hdc to picture1.hdc in the CreateCompatibleBitmap function call. here is the example to blit the picture to the top left of the form

    VB Code:
    1. BitBlt Form1.hdc, 0, 0, Form1.ScaleWidth, Form1.ScaleHeight, hdcBuffer, 0, 0, vbSrcCopy

    VB Code:
    1. 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
    2. Public Declare Function CreateCompatibleBitmap Lib "gdi32" (ByVal hdc As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long
    3. Public Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long
    4. Public Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
    5. Public Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
    6. Public Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
    7. Public Declare Function LoadImage Lib "user32" Alias "LoadImageA" (ByVal hInst As Long, ByVal lpsz As String, ByVal un1 As Long, ByVal n1 As Long, ByVal n2 As Long, ByVal un2 As Long) As Long
    8.  
    9. Public Const LR_LOADFROMFILE = &H10
    10.  
    11. Public Type BITMAPFILEHEADER
    12.         bfType As Integer
    13.         bfSize As Long
    14.         bfReserved1 As Integer
    15.         bfReserved2 As Integer
    16.         bfOffBits As Long
    17. End Type
    18. Public Type BITMAPINFOHEADER
    19.         biSize As Long
    20.         biWidth As Long
    21.         biHeight As Long
    22.         biPlanes As Integer
    23.         biBitCount As Integer
    24.         biCompression As Long
    25.         biSizeImage As Long
    26.         biXPelsPerMeter As Long
    27.         biYPelsPerMeter As Long
    28.         biClrUsed As Long
    29.         biClrImportant As Long
    30. End Type
    31. Public Type BitmapStruct
    32.         FileHeader As BITMAPFILEHEADER
    33.         InfoHeader As BITMAPINFOHEADER
    34. End Type
    35.  
    36. Dim wid&
    37. Dim hgt&
    38. Dim bm As BitmapStruct
    39. Dim hImage&
    40. Dim hdcImage&
    41. Dim hMask&
    42. Dim hdcMask&
    43. Dim hBuffer&
    44. Dim hdcBuffer&
    45. Dim FileName$
    46.  
    47.  
    48. Private Sub Form_Load()
    49.      
    50.      FileName = app.path & "\image.bmp"
    51.  
    52.      GetBitmapInfo
    53.  
    54.     wid = bm.InfoHeader.biWidth
    55.     hgt = bm.InfoHeader.biHeight
    56.     hImage = LoadImage(ByVal 0&, FileName, 0, wid, hgt, LR_LOADFROMFILE)
    57.     hdcImage = CreateCompatibleDC(0)
    58.     SelectObject hdcImage, hImage
    59.  
    60.     FileName = app.path & "\mask.bmp"
    61.  
    62.      GetBitmapInfo
    63.  
    64.     wid = bm.InfoHeader.biWidth
    65.     hgt = bm.InfoHeader.biHeight
    66.     hMask = LoadImage(ByVal 0&, FileName, 0, wid, hgt, LR_LOADFROMFILE)
    67.     hdcMask = CreateCompatibleDC(0)
    68.     SelectObject hdcMask, hMask
    69.  
    70.     hBuffer = CreateCompatibleBitmap(Form1.hdc, wid, hgt)  'change this to picture1.hdc to blit to picture boxes
    71.     hdcBuffer = CreateCompatibleDC(0)
    72.     SelectObject hdcBuffer, hBuffer  
    73.  
    74.     BitBlt hdcBuffer, 0, 0, Form1.Width, Form1.Height, hdcMask, 0, 0, vbSrcAnd
    75.     BitBlt hdcBuffer, 0, 0, Form1.Width, Form1.Height, hdcImage, 0, 0, vbSrcPaint
    76.  
    77. End Sub
    78.  
    79. Private Sub GetBitmapInfo()
    80. Dim filenum&
    81.  
    82.     filenum = FreeFile
    83.     Open FileName For Random As filenum Len = Len(bm)
    84.         Get filenum, 1, bm
    85.     Close filenum
    86.    
    87.     If Len(bm) = 0 Then
    88.         Debug.Print "Bitmap header is empty"
    89.     End If
    90.    
    91. End Sub

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2001
    Posts
    421
    Thanks Golgo, I'll try that when I get home.
    [vbcode]
    ' comment
    Rem remark
    [/vbcode]

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2001
    Posts
    421
    Ok, I did it exactly as you said, and it works, except for one thing... it causes horrible graphic glitches in the transparent area of the buffer when copied onto the main form's DC. Is it fixable? I've tried for a while messing around with it, but I can't figure anything out. Any ideas?
    [vbcode]
    ' comment
    Rem remark
    [/vbcode]

  7. #7
    Lively Member
    Join Date
    Mar 2002
    Posts
    110
    i'm at work now, i'll take a look at it, post the images if you can, otherwise i'll create my own

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2001
    Posts
    421
    Here's what's happening. No clue as to how to fix it, I've tried a lot of things.
    Attached Images Attached Images  
    [vbcode]
    ' comment
    Rem remark
    [/vbcode]

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