(table1.FieldByName('a6') as tblobfield).loadfromfile(s)
-------其中S 为要保存的图片文件名
打开图片(.jpg和.bmp都可以)var
bmp:TBitmap
jpg:TJpegImage
temp:string
sum:string
i,j:integer
jj,bb:boolean
begin
if openpicturedialog1.Execute then
begin
edit1.Text:=openpicturedialog1.FileName
bmp:=TBitmap.create
jj:= AnsiEndsText('.jpg',edit1.Text)//看看是jpg文件还是bmp文件
bb:= AnsiEndsText('.bmp',edit1.Text)
if jj then
begin
Jpg:=TJpegImage.Create
Jpg.LoadFromFile(openpicturedialog1.FileName)
bmp.assign(jpg)
jpg.free
key:=extractfilename(edit1.Text)//将jpg转化bmp
sum:=key
i:=length(sum)
i:=i-4
temp:=''
for j:=1 to i do
begin
temp:=temp+sum[j]
end
key:=temp
key:=key+'.bmp'
bmp.savetofile(key)//转化结束,因为mysql不能存jpg
biao:=1
end
else if bb then
begin
bmp.LoadFromFile(openpicturedialog1.FileName)
key:=extractfilename(edit1.Text)
biao:=0
end
image1.Picture.LoadFromFile(openpicturedialog1.FileName)
bmp.free
end
保存图片:
var
Picture1:TPicture
begin // 保存图片到数据库中
Picture1:=TPicture.create
try
try
if fileexists(edit1.text) then
with ADOtable1 do
begin
adotable1.Close
adotable1.Open
Picture1.LoadFromFile(key)
if Locate('name',extractfilename(edit1.text),[loCaseInsensitive])=false then
begin
indexfieldnames:='name'
ADOtable1.Insert
Fields[0].AsString:=extractfilename(key)
Fields[1].Assign(Picture1)
Post
showmessage('图象保存成功!')
end
else
showmessage('图象已经存在!')
end
finally
Picture1.Free
bmp1.Free
end
except
showmessage('图象保存失败!')
end
if biao=1 then
DeleteFile(key)
end
打印则qreport中的qrimage,或者是fastrepot exports中的frBMPExport和frJPEGExport!!
var Stream:TMemoryStreambegin
try
Stream := TMemoryStream.Create// 创建内存流Image1.Picture.Graphic.SaveToStream(Stream) // 将图片保存到内存流中
adoquery1.Close adoquery1.SQL.Clear adoQuery1.SQL.Add('Insert into test3 values (:id,:photo)') ADOQuery1.Parameters.ParamByName('id').Value := editId.Text adoQuery1.Parameters.ParamByName('photo').LoadFromStream(Stream,ftBlob)// 读取保存的内存图adoquery1.ExecSQL
finally
Stream.Free// 释放内存流
end
end
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)