T
tommy27149
Unregistered / Unconfirmed
GUEST, unregistred user!
简单是因为有众多高手在,重要是因为经理天天盯着
各位弟兄,救救小弟吧!!
我编写了一个关于照片存取数据库的程序可是老是报错目前主要的错是以下几种:
存入时出现的stream read error! Bitmap image is not valid 读取时出现JPEG error #53
我的代码是这样的
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DBCtrls, DB, ADODB, Grids, DBGrids, ExtCtrls, StdCtrls,jpeg,
ExtDlgs;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Image1: TImage;
Image2: TImage;
DataSource1: TDataSource;
DBGrid1: TDBGrid;
ADOQuery1: TADOQuery;
DBImage1: TDBImage;
OpenPictureDialog1: TOpenPictureDialog;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);//存入数据库
var
MyJPEG : TJPEGImage;
MS: TMemoryStream;
begin
if OpenPictureDialog1.Execute then
Image1.picture.loadfromfile(OpenPictureDialog1.FileName);
MyJPEG:=TJPEGImage.Create;
Try
MyJPEG.Assign(Image1.Picture.Graphic); {图像转成JPEG格式,如为JPEG图片则不必加}
MS:=TMemoryStream.Create;
MyJPEG.SaveToStream(MS);
MS.Position:=0;
ADOQuery1.Append;
ADOQuery1.FieldByName('image').Value:='1';
TBlobField(ADOQuery1.FieldByName('image')).LoadFromStream(MS);
ADOQuery1.Post;
messagebox(getactivewindow(),'图像保存完毕!','保存',mb_ok);
MS.Free;
Finally
MyJPEG.Free;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);读取图片
var
MyJPEG : TJPEGImage;
MS: TMemoryStream;
begin
MS:=TMemoryStream.Create;
MyJPEG:=TJPEGImage.Create;
ADOQuery1.Requery;
try
TBlobField(ADOQuery1.FieldByName('image')).SaveToStream(MS);
MS.Position:=0;
MyJPEG.LoadFromStream(MS);
Image2.Picture.Bitmap.Assign(MyJPEG);
finally
MS.Free;
MyJPEG.Free;
end;
end;
end.
敬请各位仁兄鼎立相助 帮小弟度过这一难关不胜感激!
各位弟兄,救救小弟吧!!
我编写了一个关于照片存取数据库的程序可是老是报错目前主要的错是以下几种:
存入时出现的stream read error! Bitmap image is not valid 读取时出现JPEG error #53
我的代码是这样的
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DBCtrls, DB, ADODB, Grids, DBGrids, ExtCtrls, StdCtrls,jpeg,
ExtDlgs;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Image1: TImage;
Image2: TImage;
DataSource1: TDataSource;
DBGrid1: TDBGrid;
ADOQuery1: TADOQuery;
DBImage1: TDBImage;
OpenPictureDialog1: TOpenPictureDialog;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);//存入数据库
var
MyJPEG : TJPEGImage;
MS: TMemoryStream;
begin
if OpenPictureDialog1.Execute then
Image1.picture.loadfromfile(OpenPictureDialog1.FileName);
MyJPEG:=TJPEGImage.Create;
Try
MyJPEG.Assign(Image1.Picture.Graphic); {图像转成JPEG格式,如为JPEG图片则不必加}
MS:=TMemoryStream.Create;
MyJPEG.SaveToStream(MS);
MS.Position:=0;
ADOQuery1.Append;
ADOQuery1.FieldByName('image').Value:='1';
TBlobField(ADOQuery1.FieldByName('image')).LoadFromStream(MS);
ADOQuery1.Post;
messagebox(getactivewindow(),'图像保存完毕!','保存',mb_ok);
MS.Free;
Finally
MyJPEG.Free;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);读取图片
var
MyJPEG : TJPEGImage;
MS: TMemoryStream;
begin
MS:=TMemoryStream.Create;
MyJPEG:=TJPEGImage.Create;
ADOQuery1.Requery;
try
TBlobField(ADOQuery1.FieldByName('image')).SaveToStream(MS);
MS.Position:=0;
MyJPEG.LoadFromStream(MS);
Image2.Picture.Bitmap.Assign(MyJPEG);
finally
MS.Free;
MyJPEG.Free;
end;
end;
end.
敬请各位仁兄鼎立相助 帮小弟度过这一难关不胜感激!