|
-
Jan 31st, 2001, 12:46 AM
#1
Thread Starter
Member
I´m goofing around with BitBlt right now and wondering how to get max optimization out of it.
Right now I erase the "source"-pic with .cls, but is this really the fastest way? Would it be better to blit an empty square over the old source-pic instead?
Is there any use in refreashing the source?
This is the (basic) way I figured out:
.cls source - draw source-pic - blit to dest-pic - refresh dest-pic - and back from the beginning.
Iv'e seen lots of versions...what do u think?
Someone said you could store bitmaps in an array for faster transfers with BitBlt, what does that mean?
Hope you can give me a hint, I´m quite a newbie to this.
Cheers
Balder = Viking God
VB6/VC++ Enterprise Editions
-
Jan 31st, 2001, 01:57 AM
#2
Fanatic Member
Try the FillRect API (this is the work around I am currently using).....
Code:
Private Declare Function FillRect Lib "user32" (ByVal hdc As Long, lpRect As RECT, ByVal hBrush As Long) As Long
Private Declare Function CreateSolidBrush Lib "gdi32" (ByVal crColor As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Sub Command1_Click()
Dim rct As RECT
Dim lBrsh As Long
With rct
.Right = Picture1.Width / Screen.TwipsPerPixelX
.Bottom = Picture1.Height / Screen.TwipsPerPixelY
End With
lBrsh = CreateSolidBrush(Picture1.BackColor)
FillRect Picture1.hdc, rct, lBrsh
DeleteObject lBrsh
End Sub
{Insert random techno-babble here}
{Insert quote from some long gone mofo here}
-
Feb 1st, 2001, 03:24 PM
#3
Fanatic Member
You can also use BitBlt with the vbWhiteness constant to set the background all to white. Wouldn't thta be faster, Youngbuck?
-
Feb 1st, 2001, 09:42 PM
#4
Good Ol' Platypus
If you use the .cls way, make sure to have 2 picboxes and bitblt to picbox2.
Code:
do
picbox2.cls
'... code here for bitblt (blit to picbox2!!!!!)
rc=bitblt(picbox1.hdc,0,0,picbox2.scalewidth,picbox2.scaleheight,picbox2.hdc,0,0,srccopy)
doevents
loop
Believe me; don't do it in a loop unless doing DirectDraw!
All contents of the above post that aren't somebody elses are mine, not the property of some media corporation. 
(Just a heads-up)
-
Feb 2nd, 2001, 06:51 PM
#5
Fanatic Member
Using BitBlt with the vbWhiteness constant will definitely be faster but what if you want the background to be a different color than white, that is why I suggested the FillRect API.
{Insert random techno-babble here}
{Insert quote from some long gone mofo here}
-
Feb 3rd, 2001, 08:00 AM
#6
Fanatic Member
That's correct. But you can also simply set the .BackColor property to another value, not?
-
Feb 4th, 2001, 01:58 AM
#7
Thread Starter
Member
Hm, I have seen what you have written, thanks for it. But consider I have a certain picture as background, can I still use the vbwhiteness MadCompie? How then?
Balder = Viking God
VB6/VC++ Enterprise Editions
-
Feb 4th, 2001, 06:37 PM
#8
Fanatic Member
To get the best performance try storing the picture in an Offscreen Device Context and BitBlting it to the screen when you want to repaint the background instead of using .Cls, here is a quick example ..
Code:
Option Explicit
Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
Private 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
Private lngBkGdDC As Long
Private iPic As IPictureDisp
Private lngOrigBitmap As Long
Private Sub Command1_Click()
ClearPictureBox
End Sub
Private Sub Form_Load()
Picture1.ScaleMode = vbPixels
' create a new DC in memory that is compatible with the picture box's DC
lngBkGdDC = CreateCompatibleDC(Picture1.hdc)
If Not lngBkGdDC = 0 Then
' load the picture into memory
Set iPic = LoadPicture("C:\Windows\Forest.bmp")
' load the picture into the DC and retrieve the handle to the bitmap _
created with the DC
lngOrigBitmap = SelectObject(lngBkGdDC, iPic)
Else
'if offscreen DC could not be created end the app
Unload Me
End If
End Sub
Public Sub ClearPictureBox()
' paint the offscreen dc over whatever is currently drawn in _
the picture box
BitBlt Picture1.hdc, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight, lngBkGdDC, 0, 0, vbSrcCopy
End Sub
Private Sub Form_Unload(Cancel As Integer)
'**IMPORTANT** Free Memory when the Device is no longer needed
' put the bitmap orignally created with DC back into the DC
SelectObject lngBkGdDC, lngOrigBitmap
' Delete the Picture from Memory
DeleteObject iPic
Set iPic = Nothing
' Remove the DC from memory
DeleteDC lngBkGdDC
End Sub
{Insert random techno-babble here}
{Insert quote from some long gone mofo here}
-
Feb 5th, 2001, 02:36 PM
#9
Fanatic Member
Well Balder, I think YoungBuck just gave the answer...
-
Feb 5th, 2001, 06:08 PM
#10
Thread Starter
Member
Yeah, that´s pretty much what I was looking for, thx ya all
Balder = Viking God
VB6/VC++ Enterprise Editions
-
Feb 13th, 2001, 06:00 AM
#11
Lively Member
I am also looking for a faster way to .CLS, so this looked like an ideal thread.
To check out the ideas, I wrote a simple test under a Commandbutton_Click
XX = Now
For X = 1 to 10000
execute YoungBucks FillRest Code
Next X
ZZ = Now
Debug.Print ZZ - XX
XX = Now
For X = 1 to 10000
Picture1.cls
Next X
ZZ = Now
Debug.Print ZZ - XX
Interestingly both loops took almost identical time. Looks to me like FillRect API (and its setup/teardown) is no better than .CLS
-
Feb 13th, 2001, 10:54 AM
#12
PowerPoster
...using my vB tool your code would look wayyy better Download now!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|