我理解你
創(chuàng)新互聯(lián)建站-云計算及IDC服務提供商,涵蓋公有云、IDC機房租用、德陽服務器托管、等保安全、私有云建設等企業(yè)級互聯(lián)網(wǎng)基礎服務,電話聯(lián)系:13518219792
我寫過圖片網(wǎng)絡傳輸?shù)暮湍阋蟮囊粯?/p>
為了不把圖片寫到硬盤 又從硬盤讀取
而直接保存圖片內存流 進行網(wǎng)絡傳輸
從網(wǎng)絡讀取的圖片byte數(shù)組轉成圖片代碼如下
Dim mStream As New IO.MemoryStream
mStream.Write(b, 0, b.length) '這里b就是你的一維數(shù)組了
Dim Img As New Bitmap(mStream)
mStream.Close()
mStream.Dispose()
下面是把圖片保存到一維數(shù)組的方法
Dim Stream As New IO.MemoryStream
im.Save(Stream, System.Drawing.Imaging.ImageFormat.Jpeg)
im = Nothing
Stream.Flush()
Dim b As Byte() = Stream.ToArray
Stream.Dispose()
winsock 發(fā)送圖片,就是發(fā)送文件嘛。
不過UDP協(xié)議每次最多只能發(fā)送8K,所以你要先讀取文件,建立以個byte()數(shù)組 然后第一次發(fā)送是從數(shù)組的0-8100這個范圍,下次再發(fā)送的時候將再從8101開始發(fā)送,長度仍未8100就可以了。用一個while 循環(huán)來判斷文件有沒有發(fā)送完成就行了。對于接收端,在接收的時候也是要用一個循環(huán)來寫文件,前提是你必須先把要發(fā)送的文件的長度告訴接收端。說的夠詳細了吧!
我正在用呀,沒有任何問題!你的設置可能有問題!
Private Sub Command4_Click()
If Combo1.Text = "" Then
MsgBox "請您輸入轉換格式!!", 48, "提示信息"
Exit Sub
ElseIf Text2.Text = "" Or Text3.Text = "" Then
MsgBox "請選擇轉換前和轉換后的文件路徑!!", 48, "提示信息"
Exit Sub
Else
Me.MousePointer = 11
Command4.Enabled = False
Dim i, j, w, h, w1, h1, k As Integer
w = Picture1.Width
h = Picture1.Height
w1 = w / 15
h1 = h / 15
Picture2.Width = w
Picture2.Height = h
Picture1.Scale (0, 0)-(w1, h1)
Picture2.Scale (0, 0)-(w1, h1)
For i = 1 To w1
For j = 1 To h1
Picture2.PSet (i, j), Picture1.Point(i, j)
Next j
Next i
Picture2.Picture = Picture2.Image
SavePicture Picture2.Image, Text3.Text "." Mid(Combo1.Text, 3, Len(Combo1.Text) - 1)
MsgBox "格式轉換成功完成!!", 64, "提示信息"
Command4.Enabled = True
Me.MousePointer = 0
End If
End Sub
Private Sub Command2_Click()
On Error GoTo x
DHK1.Filter = "所有文件(*.*)|*.*"
DHK1.ShowOpen
Text2.Text = DHK1.FileName
Image1.Picture = LoadPicture(Text2.Text)
Picture1.Picture = Image1.Picture
Exit Sub
x:
MsgBox "無效圖片!", 64, "提示信息"
End Sub
Private Sub Command3_Click()
DHK1.Filter = "所有文件(*.*)|*.*"
DHK1.ShowSave
Text3.Text = DHK1.FileName
End Sub
DHK1是CommonDialog控件