RayOK
02-02-2005, 02:10 PM
On my friend's machine (1gb RAM) it fails to create the compatible bitmap I need. I guess it's because the bitmap's dimensions are too big for VB6 to hold? But then again, my machine (1gb RAM also, and another with 256mb RAM) does create the bitmap. If my friend resizes the graphic loaded into imgAU1 to half its size it works. Maybe I should explain how it works and maybe then you can think of why it fails or if there is a more efficient, less memory intensive method.
'Setup
intScrnWidth = Screen.Width / Screen.TwipsPerPixelX
intScrnHeight = Screen.Height / Screen.TwipsPerPixelY
'Step 1, create my main buffer, (myBackBuffer (backbuffer park demo))
myBackBuffer = CreateCompatibleDC(GetDC(0))
'Step 2, create the compatible bitmap for myBackBuffer, size of the screen with:
myBufferBMP = CreateCompatibleBitmap(GetDC(0), intScrnWidth, intScrnHeight)
'this one works fine
'Step 3, select them together with:
SelectObject(myBackBuffer, myBufferBMP)
'Step 4) loads the main graphic in my program, which is 3260 pixels wide by 5880 pixels tall, huge
imgAU1 = LoadGraphicDC(strImageName)
'LoadGraphicDC function from backbuffer park demo, below. This also loads fine by itself
'before the objects are loaded, create the object buffer, like above, with these:
myObjectBuffer = CreateCompatibleDC(GetDC(0)) 'works fine
myObjectBMP = CreateCompatibleBitmap(GetDC(0), imgInfo.BmWidth, imgInfo.BmHeight) 'THIS is the one that fails
SelectObject myObjectBuffer, myObjectBMP 'this also fails because myObjectBMP failed
'imgInfo is the User Defined Type BITMAPINFO that was used with GetObject earlier. They are set right.
The program works mainly by the Draw() sub below.. It basically fills the buffer with black, draw the appropriate part of imgAU1 that the person wants to see then overlays the objects on top it just like the image. The Draw() sub only happens when someone pans/scrolls, zooms or at other drawing related times, like after the objects are loaded onto the buffer.
Public Function LoadGraphicDC(strFileName As String) As Long
Dim lngDCtemp As Long
lngDCtemp = CreateCompatibleDC(GetDC(0))
'load the graphic file into the DC...
SelectObject lngDCtemp, LoadPicture(strFileName)
'return the address of the file
LoadGraphicDC = lngDCtemp
End Function
Public Sub Draw()
Me.Cls
'should first fill it with black
BitBlt myBackBuffer, 0, 0, udtLayout.Width, udtLayout.Height, 0, 0, 0, vbWhiteness
'this will load the big layout graphic into the backbuffer
StretchBlt myBackBuffer, 0, 0, udtLayout.Width, udtLayout.Height, imgAU1, _
udtLayout.XSrc, udtLayout.YSrc, udtLayout.Width / sngZoom, _
udtLayout.Height / sngZoom, vbSrcPaint
'draw the objects on top of the layout
TransparentBlt myBackBuffer, 0, 0, udtLayout.Width, udtLayout.Height, myObjectBuffer, _
udtLayout.XSrc, udtLayout.YSrc, udtLayout.Width / sngZoom, udtLayout.Height / sngZoom, _
GetPixel(myObjectBuffer, 0, 0)
'loads the completed backbuffer onto the form
BitBlt Me.hdc, udtLayout.XDest, udtLayout.YDest, udtLayout.Width, udtLayout.Height, myBackBuffer, 0, 0, vbSrcCopy
Me.Refresh
End Sub
Hope this explains it.. If not, I will be happy to try again because I'm stumped.. :confused:
'Setup
intScrnWidth = Screen.Width / Screen.TwipsPerPixelX
intScrnHeight = Screen.Height / Screen.TwipsPerPixelY
'Step 1, create my main buffer, (myBackBuffer (backbuffer park demo))
myBackBuffer = CreateCompatibleDC(GetDC(0))
'Step 2, create the compatible bitmap for myBackBuffer, size of the screen with:
myBufferBMP = CreateCompatibleBitmap(GetDC(0), intScrnWidth, intScrnHeight)
'this one works fine
'Step 3, select them together with:
SelectObject(myBackBuffer, myBufferBMP)
'Step 4) loads the main graphic in my program, which is 3260 pixels wide by 5880 pixels tall, huge
imgAU1 = LoadGraphicDC(strImageName)
'LoadGraphicDC function from backbuffer park demo, below. This also loads fine by itself
'before the objects are loaded, create the object buffer, like above, with these:
myObjectBuffer = CreateCompatibleDC(GetDC(0)) 'works fine
myObjectBMP = CreateCompatibleBitmap(GetDC(0), imgInfo.BmWidth, imgInfo.BmHeight) 'THIS is the one that fails
SelectObject myObjectBuffer, myObjectBMP 'this also fails because myObjectBMP failed
'imgInfo is the User Defined Type BITMAPINFO that was used with GetObject earlier. They are set right.
The program works mainly by the Draw() sub below.. It basically fills the buffer with black, draw the appropriate part of imgAU1 that the person wants to see then overlays the objects on top it just like the image. The Draw() sub only happens when someone pans/scrolls, zooms or at other drawing related times, like after the objects are loaded onto the buffer.
Public Function LoadGraphicDC(strFileName As String) As Long
Dim lngDCtemp As Long
lngDCtemp = CreateCompatibleDC(GetDC(0))
'load the graphic file into the DC...
SelectObject lngDCtemp, LoadPicture(strFileName)
'return the address of the file
LoadGraphicDC = lngDCtemp
End Function
Public Sub Draw()
Me.Cls
'should first fill it with black
BitBlt myBackBuffer, 0, 0, udtLayout.Width, udtLayout.Height, 0, 0, 0, vbWhiteness
'this will load the big layout graphic into the backbuffer
StretchBlt myBackBuffer, 0, 0, udtLayout.Width, udtLayout.Height, imgAU1, _
udtLayout.XSrc, udtLayout.YSrc, udtLayout.Width / sngZoom, _
udtLayout.Height / sngZoom, vbSrcPaint
'draw the objects on top of the layout
TransparentBlt myBackBuffer, 0, 0, udtLayout.Width, udtLayout.Height, myObjectBuffer, _
udtLayout.XSrc, udtLayout.YSrc, udtLayout.Width / sngZoom, udtLayout.Height / sngZoom, _
GetPixel(myObjectBuffer, 0, 0)
'loads the completed backbuffer onto the form
BitBlt Me.hdc, udtLayout.XDest, udtLayout.YDest, udtLayout.Width, udtLayout.Height, myBackBuffer, 0, 0, vbSrcCopy
Me.Refresh
End Sub
Hope this explains it.. If not, I will be happy to try again because I'm stumped.. :confused: