delphi+Sql图片问题
数据库中表名为stuinfo,有字段学生姓名stuname,照片photocombobox1中选择一个学生的姓名然后怎么把相应的照片载入到数据库中?怎么从数据库中调出显示...
数据库中表名为stuinfo,有字段学生姓名 stuname,照片 photo
combobox1中选择一个学生的姓名然后怎么把相应的照片载入到数据库中?
怎么从数据库中调出显示? 展开
combobox1中选择一个学生的姓名然后怎么把相应的照片载入到数据库中?
怎么从数据库中调出显示? 展开
1个回答
展开全部
我就用我写的程序里面原一段给你吧(图片导入)
procedure TJLZYBZS_Form.SpeedButton3Click(Sender: TObject);
const
JPEG_FLAG_BEGIN = $D8FF;
JPEG_FLAG_END = $D9FF;
var
JpegStream:TMemoryStream;
Jpeg:TJpegImage;
Imageproperty:TFileStream;
Flag1,Flag2:word;
begin
try
JpegStream:=Tmemorystream.Create;
jpeg:=Tjpegimage.create;
if OpenDialog1.Execute then
begin
Imageproperty:=TFileStream.Create(OpenDialog1.FileName,fmOpenRead);
Imageproperty.Read(Flag1,SizeOf(Flag1));
Imageproperty.Position:=Imageproperty.Size-2;
Imageproperty.Read(Flag2,sizeOf(Flag2));
if not (flag1=JPEG_FLAG_BEGIN) and (flag2=JPEG_FLAG_END) then
begin
showmessage('您上传的图片格式不是*.JPEG格式!请先转换!');
SpeedButton3.Cursor:=crdefault;
JpegStream.Free;
Imageproperty.Free;
exit;
end;
Imageproperty.Free;
jpeg.LoadFromFile(OpenDialog1.FileName);
end
else
begin
SpeedButton3.Cursor:=crdefault;
exit;
end;
JpegStream.Position:=0;
Jpeg.SaveToStream(JpegStream);
with datamodule1.adoqry do
begin
active:=false;
sql.Clear;
sql.Add('update w_sulfuration set image=:image where modu_key='+''''+trim(DBEdit_modu_key.Text)+'''');
Parameters.ParamByName('image').LoadFromStream(JpegStream,FtBlob);
execsql;
end;
JpegStream.Free;
Jpeg.Free;
SpeedButton3.Cursor:=crdefault;
except
showmessage('上传失败,请再传!');
end;
showmessage('上传完毕');
end;
调出显示:
procedure TJLZYBZS_Form.SpeedButton4Click(Sender: TObject);(图片预览)
Jpegstream:TMemoryStream;
JpegFile:TJpegimage;
begin
Panel4.Visible:=true;
modu_key='+''''+trim(DBEdit_modu_key.Text)+'''' ;
with datamodule1.ADOQry do
begin
active:=false;
sql.Clear;
sql.Add(' select image from w_sulfuration where modu_key='+''''+trim(DBEdit_modu_key.Text)+'''');
open;
end;
datamodule1.ADOQry.First;
if not datamodule1.ADOQry.FieldByName('image').IsNull then
begin
JPegstream:=tmemorystream.Create;
jpegfile:=tjpegimage.Create;
TBlobfield(datamodule1.ADOQry.FieldByName('image')).SaveToStream(Jpegstream);
Jpegstream.Position:=0;
jpegfile.LoadFromStream(Jpegstream);
image1.Picture.Assign(jpegfile);
end
else begin
image1.Picture:=nil;
end;
图片打印:在打印按钮上面写以下程序
新加IMAGE
jlzybzspri_form.JLBZSPRIADOQuery.First;
if not jlzybzspri_form.JLBZSPRIADOQuery.FieldByName('image').IsNull then
begin
JpegStream:=TMemoryStream.Create;
JpegFile:=TJpegImage.Create;
TBlobField(jlzybzspri_form.JLBZSPRIADOQuery.FieldByName('image')).savetostream(JpegStream);
JpegStream.Position :=0;
Jpegfile.LoadFromStream(JpegStream);
jlzybzspri_form.QRImage1.Picture.Assign(JpegFile);
end
else begin
jlzybzspri_form.QRImage1.Picture:=nil;
end;
JLZYBZSPRI_Form.QuickRep1.Preview;
JLZYBZSPRI_Form.Free;
procedure TJLZYBZS_Form.SpeedButton3Click(Sender: TObject);
const
JPEG_FLAG_BEGIN = $D8FF;
JPEG_FLAG_END = $D9FF;
var
JpegStream:TMemoryStream;
Jpeg:TJpegImage;
Imageproperty:TFileStream;
Flag1,Flag2:word;
begin
try
JpegStream:=Tmemorystream.Create;
jpeg:=Tjpegimage.create;
if OpenDialog1.Execute then
begin
Imageproperty:=TFileStream.Create(OpenDialog1.FileName,fmOpenRead);
Imageproperty.Read(Flag1,SizeOf(Flag1));
Imageproperty.Position:=Imageproperty.Size-2;
Imageproperty.Read(Flag2,sizeOf(Flag2));
if not (flag1=JPEG_FLAG_BEGIN) and (flag2=JPEG_FLAG_END) then
begin
showmessage('您上传的图片格式不是*.JPEG格式!请先转换!');
SpeedButton3.Cursor:=crdefault;
JpegStream.Free;
Imageproperty.Free;
exit;
end;
Imageproperty.Free;
jpeg.LoadFromFile(OpenDialog1.FileName);
end
else
begin
SpeedButton3.Cursor:=crdefault;
exit;
end;
JpegStream.Position:=0;
Jpeg.SaveToStream(JpegStream);
with datamodule1.adoqry do
begin
active:=false;
sql.Clear;
sql.Add('update w_sulfuration set image=:image where modu_key='+''''+trim(DBEdit_modu_key.Text)+'''');
Parameters.ParamByName('image').LoadFromStream(JpegStream,FtBlob);
execsql;
end;
JpegStream.Free;
Jpeg.Free;
SpeedButton3.Cursor:=crdefault;
except
showmessage('上传失败,请再传!');
end;
showmessage('上传完毕');
end;
调出显示:
procedure TJLZYBZS_Form.SpeedButton4Click(Sender: TObject);(图片预览)
Jpegstream:TMemoryStream;
JpegFile:TJpegimage;
begin
Panel4.Visible:=true;
modu_key='+''''+trim(DBEdit_modu_key.Text)+'''' ;
with datamodule1.ADOQry do
begin
active:=false;
sql.Clear;
sql.Add(' select image from w_sulfuration where modu_key='+''''+trim(DBEdit_modu_key.Text)+'''');
open;
end;
datamodule1.ADOQry.First;
if not datamodule1.ADOQry.FieldByName('image').IsNull then
begin
JPegstream:=tmemorystream.Create;
jpegfile:=tjpegimage.Create;
TBlobfield(datamodule1.ADOQry.FieldByName('image')).SaveToStream(Jpegstream);
Jpegstream.Position:=0;
jpegfile.LoadFromStream(Jpegstream);
image1.Picture.Assign(jpegfile);
end
else begin
image1.Picture:=nil;
end;
图片打印:在打印按钮上面写以下程序
新加IMAGE
jlzybzspri_form.JLBZSPRIADOQuery.First;
if not jlzybzspri_form.JLBZSPRIADOQuery.FieldByName('image').IsNull then
begin
JpegStream:=TMemoryStream.Create;
JpegFile:=TJpegImage.Create;
TBlobField(jlzybzspri_form.JLBZSPRIADOQuery.FieldByName('image')).savetostream(JpegStream);
JpegStream.Position :=0;
Jpegfile.LoadFromStream(JpegStream);
jlzybzspri_form.QRImage1.Picture.Assign(JpegFile);
end
else begin
jlzybzspri_form.QRImage1.Picture:=nil;
end;
JLZYBZSPRI_Form.QuickRep1.Preview;
JLZYBZSPRI_Form.Free;
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询