vb6 写入图片变花了 有一条一条的横线

killeruser 2012-01-20 10:44:19
各位帮忙看看这段代码 为什么图片转存后变花了

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
...全文
106 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
killeruser 2012-01-20
  • 打赏
  • 举报
回复
最近 C 啊vb 都搞晕了
killeruser 2012-01-20
  • 打赏
  • 举报
回复
谢了 呵呵 没有注意
Tiger_Zhao 2012-01-20
  • 打赏
  • 举报
回复
Dim a(1024)     As Byte

数组 a 有 0~1024 共 1025 个成员,就是说你每复制一块就多出一个字节。
基础啊基础!

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧