'The Sending App, containing a PictureBox and a Command Button
'ScaleMode of the Form and the PictureBox set to Pixels
Private Const BI_RGB = 0&
Private Const DIB_RGB_COLORS = 0
Private Type BITMAPINFOHEADER
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 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 GetDIBits Lib "gdi32" _
(ByVal aHDC 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 SelectObject Lib "gdi32" _
(ByVal hdc As Long, ByVal hObject As Long) As Long
Private Declare Function DeleteDC Lib "gdi32" _
(ByVal hdc As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" _
(ByVal hObject 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 GetDC Lib "user32" _
(ByVal hwnd As Long) As Long
Dim iBitmap As Long, iDC As Long
Private Sub Command1_Click()
Dim bi24BitInfo As BITMAPINFO, bBytes() As Byte
With bi24BitInfo.bmiHeader
.biBitCount = 24
.biCompression = BI_RGB
.biPlanes = 1
.biSize = Len(bi24BitInfo.bmiHeader)
.biWidth = Picture1.Width
.biHeight = Picture1.Height
End With
ReDim bBytes(1 To bi24BitInfo.bmiHeader.biWidth * _
bi24BitInfo.bmiHeader.biHeight * 3) As Byte
iDC = CreateCompatibleDC(0)
iBitmap = CreateDIBSection(iDC, bi24BitInfo, _
DIB_RGB_COLORS, ByVal 0&, ByVal 0&, ByVal 0&)
SelectObject iDC, iBitmap
BitBlt iDC, 0, 0, bi24BitInfo.bmiHeader.biWidth, _
bi24BitInfo.bmiHeader.biHeight, Picture1.hdc, 0, 0, _
vbSrcCopy
GetDIBits iDC, iBitmap, 0, _
bi24BitInfo.bmiHeader.biHeight, bBytes(1), _
bi24BitInfo, DIB_RGB_COLORS
Open App.Path & "\CloudsCopy.BMP" For Binary As #1
Put #1, 1, CLng(Picture1.Width)
Put #1, 5, CLng(Picture1.Height)
Put #1, 9, bBytes
Close #1
DeleteDC iDC
DeleteObject iBitmap
Client.Show 'Run the client App. I used two forms in the same app
End Sub
Private Sub Form_Load()
Me.ScaleMode = vbPixels
With Picture1
.ScaleMode = vbPixels
.AutoRedraw = True
.AutoSize = True
.Picture = LoadPicture(App.Path & "\Clouds.bmp")
End With
End Sub
'The recieving App containing a pictureBox with a command button
'with the form and picturebox scalemode set to Pixels and
'autoredraw, autosize of the pictureBox set to true
Private Declare Function SetDIBitsToDevice 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 Scan As Long, ByVal NumScans _
As Long, Bits As Any, BitsInfo As BITMAPINFO, ByVal wUsage _
As Long) As Long
Private Const BI_RGB = 0&
Private Const DIB_RGB_COLORS = 0
Private Type BITMAPINFOHEADER
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 Sub Command1_Click()
Dim bi24BitInfo As BITMAPINFO, bmpWidth As Long, _
bmpHeight As Long
Dim bbBytes() As Byte
Open App.Path & "\CloudsCopy.BMP" For Binary As #1
ReDim bbBytes(1 To (LOF(1) - 8))
Get #1, 1, bmpWidth
Get #1, 5, bmpHeight
Get #1, 9, bbBytes
Close #1
With bi24BitInfo.bmiHeader
.biBitCount = 24
.biCompression = BI_RGB
.biPlanes = 1
.biSize = Len(bi24BitInfo.bmiHeader)
.biWidth = bmpWidth
.biHeight = bmpHeight
End With
Picture1.Width = bmpWidth
Picture1.Height = bmpHeight
SetDIBitsToDevice Picture1.hdc, 0, 0, _
bi24BitInfo.bmiHeader.biWidth, _
bi24BitInfo.bmiHeader.biHeight, 0, 0, 0, _
bi24BitInfo.bmiHeader.biHeight, bbBytes(1), _
bi24BitInfo, DIB_RGB_COLORS
Picture1.AutoSize = True
Picture1.Refresh
End Sub
Private Sub Form_Load()
Me.ScaleMode = vbPixels
Picture1.ScaleMode = vbPixels
End Sub