作用:将接收到的数据生成jpg文件
参数:Tfile——欲生成的文件
ByteData()接收数据的变量,类型为Byte
语句如下:
Tfile = “i:\jpg\中国地图\广东省\16230881fcb96d3de500b2c6c70002d3cd353a3efbea32.jpg”
Fnum = FreeFile()
'向二进制文件中加入下载文件的数据
Open Tfile For Binary Lock Write As #Fnum ....
Put #Fnum, , ByteData()open行出现错误提示:
文件不存在!根据open函数的定义,如果文件不在则生成文件,不知道为何会有如此提示?试过将Tfile改为:Tfile = StrConv(Tfile , vbUnicode)
运行通过,但没能看见保存的文件有没哪位高人指点一二,谢谢!
参数:Tfile——欲生成的文件
ByteData()接收数据的变量,类型为Byte
语句如下:
Tfile = “i:\jpg\中国地图\广东省\16230881fcb96d3de500b2c6c70002d3cd353a3efbea32.jpg”
Fnum = FreeFile()
'向二进制文件中加入下载文件的数据
Open Tfile For Binary Lock Write As #Fnum ....
Put #Fnum, , ByteData()open行出现错误提示:
文件不存在!根据open函数的定义,如果文件不在则生成文件,不知道为何会有如此提示?试过将Tfile改为:Tfile = StrConv(Tfile , vbUnicode)
运行通过,但没能看见保存的文件有没哪位高人指点一二,谢谢!
解决方案 »
- [高分回报]VB6.0 怎样将无边框窗体最小化到托盘
- 征集能用于usercontrol的subclass和hook的类,能实现多个实例
- MSComm1控件连续发送和接收的问题
- 怎么创建公用模块
- 这样才能这样的程序退出呢
- 在winxp pro下,jet 3.51和4.0的程序运行不一样
- 如何改变滚动条的颜色?
- 请教,谁有简体转换为繁体的工具???给多分
- VB中winscok能不能实现同一局域网不同IP段的通信
- VB+access评分系统
- 实时错误‘-2147467259(80004005)’[DBNETLIB][ConnectionRead(recv())]一般性网络错误。请检查网络文档。
- vb读取注册表后怎么进行字符串比较?
' 字节数组长度和你要写的数据长度要一致
open Tfile for binary access write as #fnum
Put #Fnum,,ByteData()
close #fnum
应该是打开文件错误,先确认一下JPG文件有没有大小,双击有没有图像显示。如果有图像,那应该诃以用OPEN打开二进制文件。
'在Form1上添加2个图片框picture1、picture2,1个命令按钮command1
'事先在picture1中装入一张JPG图片,picture2.width=picture1.width,然后picture2.height=picture1.height
Option ExplicitPrivate 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 Declare Function SetBitmapBits Lib "gdi32" (ByVal hBitmap As Long, ByVal dwCount As Long, lpBits As Any) As LongPrivate Type BITMAP
bmType As Long
bmWidth As Long
bmHeight As Long
bmWidthBytes As Long
bmPlanes As Integer
bmBitsPixel As Integer
bmBits As Long
End Type
Dim PictureBits() As Byte, PictureInfo As BITMAP, iBit As LongPrivate Sub Command1_Click()
GetObject Picture1.Image, Len(PictureInfo), PictureInfo
ReDim PictureBits(1 To PictureInfo.bmWidthBytes * PictureInfo.bmHeight) As Byte
GetBitmapBits Picture1.Image, UBound(PictureBits), PictureBits(1)
For iBit = 1 To UBound(PictureBits)
PictureBits(iBit) = 255 - PictureBits(iBit) '复制位图到一维数组
Next iBit
SetBitmapBits Picture2.Image, UBound(PictureBits), PictureBits(1) '将数组还原成图像
Picture2.Refresh
End SubPrivate Sub Form_Load()
Picture1.Picture = LoadPicture("d:\131431.jpg")
Picture2.Width = Picture1.Width
Picture2.Height = Picture1.Height
End Sub
Dim bytedata(0 To 100) As Byte
Dim fnum As Integer
Dim Tfile As String
Tfile = "d:\jpg\中国地图\广东省\16230881fcb96d3de500b2c6c70002d3cd353a3efbea32.jpg"
'Open Tfile For Binary As #1
'Close #1
fnum = FreeFile()
'向二进制文件中加入下载文件的数据
Open Tfile For Binary Lock Write As #fnum
Put #fnum, , bytedata()
Close fnumEnd Sub我在d:\建了jpg\中国地图\广东省就可以了。
在open前有使用过API函数SHCreateDirectoryEx创建文件夹,不知道是不是这个的原因?SHCreateDirectoryEx函数声明:Private Declare Function SHCreateDirectoryEx Lib "shell32" Alias "SHCreateDirectoryExA" (ByVal hwnd As Long, ByVal pszPath As String, ByVal psa As Any) As Long另请教: 如果是想创建一个二级或二级以上的文件夹,除了这个函数还有没有其它更好的办法?
权限都有的。继续跟进:
已通过手工用mkDir逐级新建文件夹,问题依然存在,排除SHCreateDirectoryEx函数出问题的可能。