# **====== 拜托拜托! 传图问题, 希望大家帮我看一下程式 =======**

Posted by CK on March 14, 1999 at 03:13:10:

我是想要把主机端的图送到使用者端后秀出, 当使用者开起程式并自动连上和接档后
按下 Commnd1 来把图秀出, 不过图都不正确, 有有人能帮我找出问题呢?

我想请大家帮我看一下....
因为每次使用者的一端接到的图都不正确
我应该怎样修正呢???

'------------------------------------------------------------------------------------------
'下面是主机端的程式

Private Declare Function GetObject Lib "gdi32" Alias "GetObjectA" (ByVal hObject As Long, ByVal nCount As Long, lpObject As Any) As Long
Private Declare Function GetBitmapBits Lib "gdi32" (ByVal hBitmap As Long, ByVal dwCount As Long, lpBits As Any) As Long

Private Type BITMAP
bmType As Long
bmWidth As Long
bmHeight As Long
bmWidthBytes As Long
bmHeightBytes As Long
bmPlanes As Integer
bmBitsPixel As Integer
bmBits As Long
End Type

Dim byteAry() As Byte
Dim byteAry1() As Byte
Dim byteAry2() As Byte
Dim totbyte As Long, totbyte1 As Long, totbyte2 As Long, I As Long, J As Long

Private Sub Form_Load()
Winsock1(0).LocalPort = 5607
Winsock1(0).Listen
Load Winsock1(1)

End Sub

Private Sub Winsock1_ConnectionRequest(Index As Integer, ByVal requestID As Long)

Dim hBitmap As Long
Dim res As Long
Dim bmp As BITMAP
Dim totbyte As Long, I As Long
hBitmap = Picture1.Image

Winsock1(Index + 1).Accept requestID

res = GetObject(hBitmap, Len(bmp), bmp)

totbyte = bmp.bmWidthBytes * bmp.bmHeight

ReDim byteAry(totbyte - 1)
res = GetBitmapBits(hBitmap, totbyte, byteAry(0))

Winsock1(1).SendData byteAry
DoEvents

End Sub

'------------------------------------------------------------------------------------------
'下面是使用者端的程式

Private Declare Function SetBitmapBits Lib "gdi32" (ByVal hBitmap As Long, ByVal dwCount As Long, lpBits As Any) As Long
Dim totbyte As Long
Dim byteAry1() As Byte

Private Sub Form_Load()
Winsock1(0).RemoteHost = "207.171.241.146"
Winsock1(0).RemotePort = 5607
Winsock1(0).Connect
totbyte = 0

End Sub

Private Sub Command1_Click()

Dim Rval As Long
Rval = SetBitmapBits(Picture2.Image, totbyte, byteAry1(0))
Picture2.Refresh

End Sub

Private Sub Winsock1_DataArrival(Index As Integer, ByVal bytesTotal As Long)

ReDim Preserve byteAry1(totbyte)
Winsock1(Index).GetData byteAry1(totbyte), vbArray + vbByte
DoEvents

totbyte = Winsock1(Index).BytesReceived

End Sub

Follow Ups:

- 你只传Bitmap的Data过去，没有传Bitmap的Header(无内文) cww 13:57:18 3/15/99 (3)
  - Re: 那我该怎么做呢?(无内文) CK 16:00:50 3/15/99 (2)
    - 存成.Bmp档案后再传出 cww 08:15:57 3/16/99 (1)
      - Re: 存成.Bmp档案后再传出 CK 10:36:47 3/17/99 (0)
- Re: **====== 拜托拜托! 传图问题, 希望大家帮我看一下程式 =======** CK 03:15:26 3/14/99 (0)