P
plapla
Unregistered / Unconfirmed
GUEST, unregistred user!
环境为DELPHI6+SQL2000,表IMAGETEST有字段FIMAGE,类型为IMAGE.
插入图片:
procedure TForm1.Button2Click(Sender: TObject);
var
graphic1:TJpegImage;
MS:TMemoryStream;
//file_name:string;
begin
//file_name:=edpicname.Text;
MS:=TMemoryStream.Create;
graphic1:=TJpegImage.Create;
Image1.Picture.LoadFromFile(opendialog1.filename);
graphic1.LoadFromFile(opendialog1.filename);
graphic1.SaveToStream(MS);
MS.Position:=0;
with query1 do
begin
sql.Clear;
sql.Add('insert into imagetest(fimage) valuesFIMAGE) ');
//ParamByName('FIMAGE').LoadFromfile(opendialog1.filename,FtBlob);
ParamByName('FIMAGE').LoadFromStream(MS,FtBlob);
ExecSQL;
end;
graphic1.free;
end;
读出代码:
procedure TForm1.Button3Click(Sender: TObject);
var
MS:TMEmoryStream;
JpegImage:TJpegImage;
f: file of Byte;
begin
JpegImage:= TJpegImage.Create;
MS:=TMEmoryStream.Create;
with Query1 do
begin
close;
sql.Clear;
sql.add('select fimage from imagetest');
open;
while not EOF do
begin
next;
end;
try
TBlobField(FieldByName('fimage')).SaveToFile('tmp.jpg');
//if GetFileSize('tmp.jpg')>0 then //文件长度为0装入会出错
//begin
AssignFile(f,'tmp.jpg');
Reset(f);
if filesize(f)>0 then showmessage('save success');
closefile(f);
JpegImage.LoadFromFile('tmp.jpg');
Image2.Picture.LoadFromFile('tmp.jpg');
//end;
finally
JpegImage.Free;
end;
end;
end;
可是经测试,大于32K的图片显示就不完整,怎么解决???
插入图片:
procedure TForm1.Button2Click(Sender: TObject);
var
graphic1:TJpegImage;
MS:TMemoryStream;
//file_name:string;
begin
//file_name:=edpicname.Text;
MS:=TMemoryStream.Create;
graphic1:=TJpegImage.Create;
Image1.Picture.LoadFromFile(opendialog1.filename);
graphic1.LoadFromFile(opendialog1.filename);
graphic1.SaveToStream(MS);
MS.Position:=0;
with query1 do
begin
sql.Clear;
sql.Add('insert into imagetest(fimage) valuesFIMAGE) ');
//ParamByName('FIMAGE').LoadFromfile(opendialog1.filename,FtBlob);
ParamByName('FIMAGE').LoadFromStream(MS,FtBlob);
ExecSQL;
end;
graphic1.free;
end;
读出代码:
procedure TForm1.Button3Click(Sender: TObject);
var
MS:TMEmoryStream;
JpegImage:TJpegImage;
f: file of Byte;
begin
JpegImage:= TJpegImage.Create;
MS:=TMEmoryStream.Create;
with Query1 do
begin
close;
sql.Clear;
sql.add('select fimage from imagetest');
open;
while not EOF do
begin
next;
end;
try
TBlobField(FieldByName('fimage')).SaveToFile('tmp.jpg');
//if GetFileSize('tmp.jpg')>0 then //文件长度为0装入会出错
//begin
AssignFile(f,'tmp.jpg');
Reset(f);
if filesize(f)>0 then showmessage('save success');
closefile(f);
JpegImage.LoadFromFile('tmp.jpg');
Image2.Picture.LoadFromFile('tmp.jpg');
//end;
finally
JpegImage.Free;
end;
end;
end;
可是经测试,大于32K的图片显示就不完整,怎么解决???