"Rick Raisley" <heavymetal-A-T-bellsouth-D-O-T-net>wrote in message
Quote
>[From Mike Williams] I never said that, Rick. I think you've
>misunderstood what I actually did say.
Yes, I did, sorry. I thought the intimation was that the memory usage,
or rather limitation, was the same regardless of the control, which
is not what you said.
That's okay, Rick. It is very easy to fail to make oneself clear (as I
apparently failed to do) when typing a quick response to a newsgroup
question, and it is therefore understandable that people will occasionally
misinterpret what you have said. No problem.
Quote
I'm not familiar with this method. It still isn't possible to display
a much larger PictureBox, is it?
I'm not sure what method you are referring to Rick, but the short answer is
that a VB Autoredraw Picture Box has limitations as to how large it can be,
which are mostly system dependent, and there is no way to overcome that
limitation (other than using somehting other than a VB Autoredraw Picture
Box).
Quote
How would one draw, and then use (display and print), very
large memory bitmaps such as that? I've printed large bitmaps
by doing one section of the total image at time in a PictureBox
then PaintPicture'ing it to the printer.
Actually I think that Vista has "upped the ante" a bit on the compatible
bitmap stuff, because in Vista I can create some extremely large VB
Autoredraw picture Boxes, very much larger than I could have created in XP.
But large memory bitmaps created as a DIBSection (or as multiple
DIBSections) can be used in all versions of Windows. Here (below) is a
rather hastily modified version of some code I was working on ages ago that
shows how to create a DIBSection and how to draw into it and how to draw the
result into a device (screen or printer). This specific example creates a
DIB of the size you mentioned in your post (6154 x 7548 pixels at 24 bit
colour depth). Don't take it as a fully finished example though. It is just
something that I was playing with. Let me know if it succeeds in creating
the 6154 x 7548 pixel DIB on your own machine, which you will know by the
fact that it draws part of the DIB into your Form. You can go a lot deeper
than tbhis of course. The example is just a "starter".
Quote
That [metafiles] may be beyond the learning curve I want
to get into right now, too, but thanks for the idea.
No problem. Just post again if you want to know how to handle them. They
really are very useful, especially if you are currently using bitmaps. A
typical metafile is just a very tiny fraction of the size of the bitmap that
it draws into a device.
Mike
Option Explicit
Private Declare Function CreateCompatibleDC Lib "gdi32" _
(ByVal hDC As Long) As Long
Private Declare Function CreateDIBSection Lib "gdi32" _
(ByVal hDC As Long, pBitmapInfo As BITMAPINFO, _
ByVal un As Long, ByVal lplpVoid As Long, _
ByVal handle As Long, ByVal dw 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 Declare Function CreatePen Lib "gdi32" _
(ByVal nPenStyle As Long, ByVal nWidth As Long, _
ByVal crColor As Long) As Long
Private Declare Function LineTo Lib "gdi32" _
(ByVal hDC As Long, ByVal x As Long, ByVal y As Long) As Long
Private Const BI_RGB = 0&
Private Const DIB_RGB_COLORS = 0 ' color table in RGBs
Private Type BITMAPINFOHEADER '40 bytes
biSize As Long
biWidth As Long
biHeight As Long
biPlanes As Integer
biBitCount As Integer
biCompression As Long
biSizeImage As Long
biXPelsPerMeter As Long
biYPelsPerMeter As Long
biClrUsed As Long
biClrImportant As Long
End Type
Private Type RGBQUAD
rgbBlue As Byte
rgbGreen As Byte
rgbRed As Byte
rgbReserved As Byte
End Type
Private Type BITMAPINFO
bmiHeader As BITMAPINFOHEADER
bmiColors As RGBQUAD
End Type
Private Const PS_SOLID = 0
Private Sub Command1_Click()
Dim pixWide As Long, pixHigh As Long, n As Long
Dim myDC As Long, myDIB As Long, oldBmp As Long
Dim pen1 As Long, penOld As Long
Dim bi24BitInfo As BITMAPINFO
pixWide = 6154
pixHigh = 7548
' set the pixel size and the colour depth of the DIB
With bi24BitInfo.bmiHeader
.biBitCount = 24 ' colour depth
.biCompression = BI_RGB
.biPlanes = 1
.biSize = Len(bi24BitInfo.bmiHeader)
.biWidth = pixWide
.biHeight = pixHigh
' Note: using a negative value for the height (pixHigh) would
' allow us to treat the DIB data as starting at the top left
' corner of the image instead of the default bottom left
' corner (so it agrees with the standard VB arrangement)
' because it reverses the vertical polarity of the "draw"
' when blitting etc the DIB. However, this is at odds with
' a standard "bottom up" DIB arrangement as held in a
' standard .bmp file and the standard "bottom up"
' arrangement that we would have if we used LoadImage
' API to load a bmp file into a DIB. Therefore it is best to
' use a normal positive value for the height and leave the
' DIB with its standard default behaviour. This means that
' if we want to have our "draw bytes into the DIB" code to
' behave in the same way as Pset and SetPixel etc would
' behave (zero is the coordinate at the top) we must make
' the conversion in our code (as we have done below
' using the yInvert variable), but in a native code compiled
' exe this little addition takes almost no time at all.
End With
myDC = CreateCompatibleDC(Me.hDC)
' Create the DIB (note: I'm not sure whether the DIB pixels are
' automatically set to black (0) by Windows when the DIB is
' created, but they seem to be. Perhaps it might be wise to
' fill the DIB with the required background colour juts in case,
' but we can leave that for the moment.
Dim z As Long
'myDIB = CreateDIBSection(myDC, bi24BitInfo, _
DIB_RGB_COLORS, ByVal 0&, ByVal 0&, ByVal 0&)
myDIB = CreateDIBSection(myDC, bi24BitInfo, _
DIB_RGB_COLORS, VarPtr(z), ByVal 0&, ByVal 0&)
If myDIB = 0 Then
DeleteDC myDC
MsgBox "Unable to create DIBSection (probably too large)"
Exit Sub
End If
'myDIB = CreateCompatibleBitmap(Me.hdc, pixWide, pixHigh)
oldBmp = SelectObject(myDC, myDIB)
pen1 = CreatePen(myDC, PS_SOLID, vbRed)
penOld = SelectObject(myDC, pen1)
' draw a diagonal line into the DIB using Pen1
LineTo myDC, pixWide, pixHigh
' Blit the DIB (or at least that part of it which will fit) into
' the Form just to show that we succeeded in creating
' a DIB and drawing into it.
BitBlt Me.hDC, 0, 0, pixWide, pixHigh, _
myDC, 0, 0, vbSrcCopy
' clear up before finishing
SelectObject myDC, oldBmp ' restore the original default single pixel bitmap
DeleteObject myDIB ' delete the DIB we created
SelectObject myDC, penOld ' restore the default pen
DeleteObject pen1 ' delete the pen we created
DeleteDC myDC ' delete the DC we created
End Sub
-