请教vb保存图片的问题 我想让窗体里的控件picture1中的图象在打开一张图片后自动保存在当前目录下,保存的文件夹名是Time函数返回的系统时间,如果没有文件夹则自动新建 该如何实现?? 望各位大侠帮忙 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 '添加 Command1 Picture1'下面这个代码是将你c:\1.jpg读到Picture1里面, 图片名称自己改'在你的app.path下检查如没有test这个文件夹则自动创建一个'保存你的Picture1到app.path下面的test文件夹里面以目前时分秒命名的.bmp.Dim appdisk$, fname$Private Sub Command1_Click() appdisk = IIf(Right(App.Path, 1) = "\", App.Path, App.Path & "\") Picture1.Picture = LoadPicture("c:\1.jpg") If Dir(appdisk & "test", vbDirectory) = "" Then MkDir appdisk & "test" fname = Replace(Time$, ":", "") SavePicture Picture1.Image, appdisk & "test\" & fname & ".bmp"End Sub mkdir 使用方法已给你了, 如有需要的话则自己改改吧. 方法二 你要用 app.path 最好在 app.path下面再建立一个图片文件夹则路径将变成app.path & "\PicBox\???.jpg"保存图片之前最好先处理为 .jpg 否则你将受不了大量的.bmp图片占用的空间. 直接将图片保存到数据库里面, 此法如果你的图片很多的话, 我不建议你用这方法. 老师我也是这个想法,所以想用您说的第二种方法来解决,但又不是同一台电脑上用.我按您的代码改了改不知道行不行,老师您帮我看看.我建了两个窗体和一个模块,在form1里添加了image1和command1,command2,在form2里添加了image1,在模块中声明了一个图片存储的路径变量:strpic在form1添加了代码: Dim appdisk$, fname$Dim strname As StringPrivate Sub Command1_Click()dig.Filter = "位图文件(*.bmp)|*.bmp|位图(*.jpg)|*.jpg|所有文件(*.*)|*.*"dig.ShowOpenstrname = dig.FileTitle appdisk = IIf(Right(App.Path, 1) = "\", App.Path, App.Path & "\") fname = Right(Year(Now), 2) & "_" & Format(Month(Now), "00") Image1.Picture = LoadPicture(strname) If Dir(appdisk & "pohto", vbDirectory) = "" Then MkDir appdisk & "pohto" If Dir(appdisk & "pohto" & "\" & fname, vbDirectory) = "" Then MkDir appdisk & "\pohto" & "\" & fname' fname = Replace(Time$, ":", "") If strname <> "" Then SavePicture Image1.Picture, appdisk & "pohto\" & fname & "\" & strname' SavePicture Image1.Picture, appdisk & "test\" & strname ' strpic = appdisk & "test\" & strname strpic = appdisk & "pohto\" & fname & "\" & strnameEnd SubPrivate Sub Command2_Click()Form2.ShowEnd Sub在form2添加了代码: Private Sub Form_Load()Image1.Picture = LoadPicture(strpic)End Sub然后把strpic符值给一个表里面的某一字段,不知道这样在另一台电脑上使用时行不行.还望老师赐教! 1.我把你的Form1改了一下Dim appdisk$, PicFolder$, fname$, strname$Private Sub Command1_Click() On Error GoTo errhandle Dig.Filter = "位图格式(*.bmp)|*.bmp|GIF格式(*.gif)|*.gif|JPEG格式(*.jpg)|*.jpg" Dig.ShowOpen strname = Dig.FileTitle appdisk = IIf(Right(App.Path, 1) = "\", App.Path, App.Path & "\") '本地路径 PicFolder = appdisk & "photo\" '图片区文件夹路径 fname = Right(Year(Now), 2) & "_" & Format(Month(Now), "00") Image1.Picture = LoadPicture(strname) If Dir(PicFolder, vbDirectory) = "" Then MkDir PicFolder If Dir(PicFolder & fname, vbDirectory) = "" Then MkDir PicFolder & fname strpic = PicFolder & fname & "\" & strname MsgBox strpic SavePicture Image1.Picture, strpicerrhandle: If Err > 0 Then Exit SubEnd SubPrivate Sub Command2_Click() Form2.ShowEnd Sub2.这点你要特别注意, strpic 这个变量你要从Form1带到Form2去使用, 你最好多加一个标准模块 .bas 这样strpic变量才是 全局变量, Form2才调用得到Module1.bas 的内容(我现只给你加了一行)Public strpic$******** 你的代码告一段落后发给我, 我再帮你整理吧[email protected] FORM1的代码, 再整理一下Dim appdisk$, PicFolder$, fname$, strname$Private Sub Form_Load() appdisk = IIf(Right(App.Path, 1) = "\", App.Path, App.Path & "\") '本地路径 PicFolder = appdisk & "photo\" '图片区文件夹路径 If Dir(PicFolder, vbDirectory) = "" Then MkDir PicFolderEnd SubPrivate Sub Command1_Click() On Error GoTo errhandle Dig.Filter = "位图格式(*.bmp)|*.bmp|GIF格式(*.gif)|*.gif|JPEG格式(*.jpg)|*.jpg" Dig.ShowOpen strname = Dig.FileTitle Image1.Picture = LoadPicture(strname) fname = Right(Year(Now), 2) & "_" & Format(Month(Now), "00") If Dir(PicFolder & fname, vbDirectory) = "" Then MkDir PicFolder & fname strpic = PicFolder & fname & "\" & strname SavePicture Image1.Picture, strpicerrhandle: If Err > 0 Then Exit SubEnd SubPrivate Sub Command2_Click() Form2.ShowEnd Sub 晕 搞错了 你的 strpic 不是变量 而是文件路径, ^_^ 别管 Module1.bas 了 哎.....我今天到底是怎么了, 一方面耳朵在痛, 再方面心里掂念着老乡四川, 都乱套了.....你的 strpic 是个变量 需要加上 .bas 谢谢老师,辛苦了,在这沉痛的日子里还让您为我操心.我完成后发给你.我还想请教老师下我的一个打印问题,您能抽空帮我看下要怎么来写?我的问题贴在这里:http://topic.csdn.net/u/20080519/12/8f3fd5f1-ce29-4b1c-bd41-74c60673c604.html再次谢谢老师!!! 新人请老师指点 TeeChart 问题求教 spread设置列宽 怎么用子窗体调用父窗体控件急急急!! 求助!请熟悉ListView的高手帮忙 用Setup Factory 制作打包,更改安装目录出现的问题! 关于sstab控件,急! 寻找有关md5和dse源代码,最好是vb的 如何得知光标在文本框中的位置? 安装Dos6.22后,原来的D盘找不到了。硬盘15G,现在只有C盘1.99G了。怎么找回D盘? 我的电脑没有Winsock控件,怎么办? PeekMessage的返回值
'下面这个代码是将你c:\1.jpg读到Picture1里面, 图片名称自己改
'在你的app.path下检查如没有test这个文件夹则自动创建一个
'保存你的Picture1到app.path下面的test文件夹里面以目前时分秒命名的.bmp.Dim appdisk$, fname$
Private Sub Command1_Click()
appdisk = IIf(Right(App.Path, 1) = "\", App.Path, App.Path & "\")
Picture1.Picture = LoadPicture("c:\1.jpg")
If Dir(appdisk & "test", vbDirectory) = "" Then MkDir appdisk & "test"
fname = Replace(Time$, ":", "")
SavePicture Picture1.Image, appdisk & "test\" & fname & ".bmp"
End Sub
说的第二种方法来解决,但又不是同一台电脑上用.我按您的代码改了改不知道行不行,老师您帮我看看.
我建了两个窗体和一个模块,在form1里添加了image1和command1,command2,在form2里添加了image1,在模块中声明了一个图片存储的路径变量:strpic
在form1添加了代码:
Dim appdisk$, fname$
Dim strname As String
Private Sub Command1_Click()
dig.Filter = "位图文件(*.bmp)|*.bmp|位图(*.jpg)|*.jpg|所有文件(*.*)|*.*"
dig.ShowOpen
strname = dig.FileTitle
appdisk = IIf(Right(App.Path, 1) = "\", App.Path, App.Path & "\")
fname = Right(Year(Now), 2) & "_" & Format(Month(Now), "00")
Image1.Picture = LoadPicture(strname)
If Dir(appdisk & "pohto", vbDirectory) = "" Then MkDir appdisk & "pohto"
If Dir(appdisk & "pohto" & "\" & fname, vbDirectory) = "" Then MkDir appdisk & "\pohto" & "\" & fname
' fname = Replace(Time$, ":", "")
If strname <> "" Then SavePicture Image1.Picture, appdisk & "pohto\" & fname & "\" & strname
' SavePicture Image1.Picture, appdisk & "test\" & strname
' strpic = appdisk & "test\" & strname
strpic = appdisk & "pohto\" & fname & "\" & strname
End SubPrivate Sub Command2_Click()
Form2.Show
End Sub
在form2添加了代码:
Private Sub Form_Load()
Image1.Picture = LoadPicture(strpic)
End Sub
然后把strpic符值给一个表里面的某一字段,不知道这样在另一台电脑上使用时行不行.
还望老师赐教!
Private Sub Command1_Click()
On Error GoTo errhandle
Dig.Filter = "位图格式(*.bmp)|*.bmp|GIF格式(*.gif)|*.gif|JPEG格式(*.jpg)|*.jpg"
Dig.ShowOpen
strname = Dig.FileTitle
appdisk = IIf(Right(App.Path, 1) = "\", App.Path, App.Path & "\") '本地路径
PicFolder = appdisk & "photo\" '图片区文件夹路径
fname = Right(Year(Now), 2) & "_" & Format(Month(Now), "00")
Image1.Picture = LoadPicture(strname)
If Dir(PicFolder, vbDirectory) = "" Then MkDir PicFolder
If Dir(PicFolder & fname, vbDirectory) = "" Then MkDir PicFolder & fname
strpic = PicFolder & fname & "\" & strname
MsgBox strpic
SavePicture Image1.Picture, strpic
errhandle:
If Err > 0 Then Exit Sub
End SubPrivate Sub Command2_Click()
Form2.Show
End Sub2.这点你要特别注意, strpic 这个变量你要从Form1带到Form2去使用, 你最好多加一个标准模块 .bas 这样strpic变量才是 全局变量, Form2才调用得到
Module1.bas 的内容(我现只给你加了一行)Public strpic$
******** 你的代码告一段落后发给我, 我再帮你整理吧[email protected]
Private Sub Form_Load()
appdisk = IIf(Right(App.Path, 1) = "\", App.Path, App.Path & "\") '本地路径
PicFolder = appdisk & "photo\" '图片区文件夹路径
If Dir(PicFolder, vbDirectory) = "" Then MkDir PicFolder
End SubPrivate Sub Command1_Click()
On Error GoTo errhandle
Dig.Filter = "位图格式(*.bmp)|*.bmp|GIF格式(*.gif)|*.gif|JPEG格式(*.jpg)|*.jpg"
Dig.ShowOpen
strname = Dig.FileTitle
Image1.Picture = LoadPicture(strname)
fname = Right(Year(Now), 2) & "_" & Format(Month(Now), "00")
If Dir(PicFolder & fname, vbDirectory) = "" Then MkDir PicFolder & fname
strpic = PicFolder & fname & "\" & strname
SavePicture Image1.Picture, strpic
errhandle:
If Err > 0 Then Exit Sub
End SubPrivate Sub Command2_Click()
Form2.Show
End Sub
看下要怎么来写?
我的问题贴在这里:
http://topic.csdn.net/u/20080519/12/8f3fd5f1-ce29-4b1c-bd41-74c60673c604.html
再次谢谢老师!!!