VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "FastDrawing"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Private Type Bitmap
    bmType As Long
    bmWidth As Long
    bmHeight As Long
    bmWidthBytes As Long
    bmPlanes As Integer
    bmBitsPixel As Integer
    bmBits As Long
End Type
Private Declare Function GetObject Lib "gdi32" Alias "GetObjectA" (ByVal hObject As Long, ByVal nCount As Long, ByRef lpObject As Any) As Long
Private Type RGBQUAD
        rgbBlue As Byte
        rgbGreen As Byte
        rgbRed As Byte
        rgbAlpha As Byte
End Type
Private Type BITMAPINFOHEADER
        bmSize As Long
        bmWidth As Long
        bmHeight As Long
        bmPlanes As Integer
        bmBitCount As Integer
        bmCompression As Long
        bmSizeImage As Long
        bmXPelsPerMeter As Long
        bmYPelsPerMeter As Long
        bmClrUsed As Long
        bmClrImportant As Long
End Type
Private Type BITMAPINFO
        bmHeader As BITMAPINFOHEADER
        bmColors(0 To 255) As RGBQUAD
End Type
Dim bm As Bitmap
Dim bmi As BITMAPINFO
Dim bmLen As Long
Private Declare Function GetDIBits Lib "gdi32" (ByVal hdc As Long, ByVal hBitmap As Long, ByVal nStartScan As Long, ByVal nNumScans As Long, lpBits As Any, lpBI As BITMAPINFO, ByVal wUsage As Long) As Long
Private Declare Function StretchDIBits Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal dX As Long, ByVal dy As Long, ByVal SrcX As Long, ByVal SrcY As Long, ByVal SrcWidth As Long, ByVal SrcHeight As Long, lpBits As Any, lpBitsInfo As BITMAPINFO, ByVal wUsage As Long, ByVal dwRop As Long) As Long

Public Function GetImageWidth(SrcPictureBox As PictureBox) As Long
    GetObject SrcPictureBox.Image, bmLen, bm
    GetImageWidth = bm.bmWidth - 1
End Function

Public Function GetImageHeight(SrcPictureBox As PictureBox) As Long
    GetObject SrcPictureBox.Image, bmLen, bm
    GetImageHeight = bm.bmHeight
End Function

Public Function GetImageStreamLength(SrcPictureBox As PictureBox) As Long
    GetObject SrcPictureBox.Image, bmLen, bm
    GetImageStreamLength = (bm.bmWidth * bm.bmHeight) * 3
End Function

Public Sub GetImageData(SrcPictureBox As PictureBox, ImageData() As Byte)
    GetObject SrcPictureBox.Image, bmLen, bm
    ReDim ImageData(0 To 2, 0 To bm.bmWidth - 1, 0 To bm.bmHeight)
    bmi.bmHeader.bmWidth = bm.bmWidth
    bmi.bmHeader.bmHeight = bm.bmHeight
    GetDIBits SrcPictureBox.hdc, SrcPictureBox.Image, 0, bm.bmHeight, ImageData(0, 0, 0), bmi, 0
End Sub

Public Sub SetImageData(DstPictureBox As PictureBox, ImageData() As Byte)
    GetObject DstPictureBox.Image, bmLen, bm
    bmi.bmHeader.bmWidth = bm.bmWidth
    bmi.bmHeader.bmHeight = bm.bmHeight
    StretchDIBits DstPictureBox.hdc, 0, 0, bm.bmWidth, bm.bmHeight, 0, 0, bm.bmWidth, bm.bmHeight, ImageData(0, 0, 0), bmi, 0, vbSrcCopy
    If DstPictureBox.AutoRedraw = True Then
        DstPictureBox.Picture = DstPictureBox.Image
        DstPictureBox.Refresh
    End If
    DoEvents
End Sub

Public Sub GetImageDataStream(SrcPictureBox As PictureBox, ImageData() As Byte)
    GetObject SrcPictureBox.Image, bmLen, bm
    ReDim ImageData(0 To GetImageStreamLength(SrcPictureBox))
    bmi.bmHeader.bmWidth = bm.bmWidth
    bmi.bmHeader.bmHeight = bm.bmHeight
    GetDIBits SrcPictureBox.hdc, SrcPictureBox.Image, 0, bm.bmHeight, ImageData(0), bmi, 0
End Sub

Public Sub SetImageDataStream(DstPictureBox As PictureBox, ImageData() As Byte)
    GetObject DstPictureBox.Image, bmLen, bm
    bmi.bmHeader.bmWidth = bm.bmWidth
    bmi.bmHeader.bmHeight = bm.bmHeight
    StretchDIBits DstPictureBox.hdc, 0, 0, bm.bmWidth, bm.bmHeight, 0, 0, bm.bmWidth, bm.bmHeight, ImageData(0), bmi, 0, vbSrcCopy
    If DstPictureBox.AutoRedraw = True Then
        DstPictureBox.Picture = DstPictureBox.Image
        DstPictureBox.Refresh
    End If
    DoEvents
End Sub

Private Sub Class_Initialize()
    bmLen = Len(bm)
    bmi.bmHeader.bmSize = 40
    bmi.bmHeader.bmPlanes = 1
    bmi.bmHeader.bmBitCount = 24
    bmi.bmHeader.bmCompression = 0
End Sub
