vb6 写入图片变花了 有一条一条的横线
各位帮忙看看这段代码 为什么图片转存后变花了
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Dim data() As Byte
Dim a(1024) As Byte
data = GetFilebytes("D:\c.jpg")
Dim i As Long
Dim l As Integer
l = Fix(UBound(data) / 1024) - 1
Dim n As Long
For i = 0 To l
n = i * 1024
CopyMemory ByVal VarPtr(a(0)), ByVal VarPtr(data(n)), 1024
If WriteFile("D:\l.jpg", a) Then
Me.Text1.Text = "ok-" & CStr(i)
End If
Next
CopyMemory ByVal VarPtr(a(0)), ByVal VarPtr(data(i * 1024)), UBound(data) Mod 1024
If WriteFile("D:\l.jpg", a) Then
Me.Text1.Text = "ok-" & CStr(i)
End If
Public Function GetFilebytes(File As String) As Byte()
On Error GoTo Err
Dim data() As Byte
Dim n As Integer
n = FreeFile
Open File For Binary As #n
ReDim data(LOF(n))
Get #n, , data
GetFilebytes = data
Close #n
Exit Function
Err:
On Error GoTo 0
GetFilebytes = data
Exit Function
End Function
Public Function WriteFile(File As String, data() As Byte) As Boolean
WriteFile = False
On errror GoTo Err
Dim n As Integer
n = FreeFile
Open File For Binary As #n
Seek #n, LOF(n) + 1
Put #n, , data
Close #n
WriteFile = True
Exit Function
Err:
On Error GoTo 0
Exit Function
End Function
[解决办法]
Dim a(1024) As Byte