我的程序错在哪里?请指教!(8分)

  • 主题发起人 主题发起人 huangli_nj
  • 开始时间 开始时间
H

huangli_nj

Unregistered / Unconfirmed
GUEST, unregistred user!
unit main;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, ADODB, StdCtrls, ExtCtrls, ExtDlgs;

type
TForm1 = class(TForm)
Panel1: TPanel;
Panel2: TPanel;
Image1: TImage;
Label1: TLabel;
Edit1: TEdit;
Button1: TButton;
ADOConnection1: TADOConnection;
ADOQuery1: TADOQuery;
Image2: TImage;
OpenPictureDialog1: TOpenPictureDialog;
Button2: TButton;
Button3: TButton;
Label2: TLabel;
Edit2: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

uses GIFImage;

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
SourceStream: TMemoryStream;
DestStream: TMemoryStream;
Buffer: PChar;
Count: Integer;
MyGif : TGIFImage;
imgSeal:TMemoryStream;
begin
myGif:=TGIFImage.Create;
myBmp:=TBitmap.Create;
imgSeal:=TMemoryStream.Create;
DestStream := TMemoryStream.Create;
with ADOQuery1 do
begin
close;
sql.Clear;
sql.Add('select SDImage from sealdata where code='+''''+trim(Edit2.Text)+'''');
Open;
if(RecordCount<=0) then
else
begin
TBlobField(ADOQuery1.FieldByName('SDImage')).SaveToStream(imgSeal);
imgSeal.ReadBuffer(Count, SizeOf(Count));
GetMem(Buffer, Count);
SourceStream:= TMemoryStream.Create;
SourceStream.WriteBuffer(Buffer^, Count);

//将原始图像流保存至 DestStream流中
DestStream.Position := 0;//复位流指针
DestStream.WriteBuffer(Buffer^, Count);
myGif.LoadFromStream(DestStream);
image2.Picture.Assign(myGif);
end;
end;
end;

end.
就是为了把储存在数据库中图片显示出来,是压缩过的gif格式的图片
 
SourceStream.ReadBuffer(Buffer^,Count)
 
不行 报错信息是:'Stream Read Error' 为什么?请指教!
 
整个:
TBlobField(ADOQuery1.FieldByName('SDImage')).SaveToStream(imgSeal);
imgSeal.ReadBuffer(Count, SizeOf(Count));
GetMem(Buffer, Count);
SourceStream:= TMemoryStream.Create;
SourceStream.WriteBuffer(Buffer^, Count);

//将原始图像流保存至 DestStream流中
DestStream.Position := 0;//复位流指针
DestStream.WriteBuffer(Buffer^, Count);
myGif.LoadFromStream(DestStream);
image2.Picture.Assign(myGif);
换成:
TBlobField(ADOQuery1.FieldByName('SDImage')).SaveToStream(DestStream);
myGif.LoadFromStream(DestStream);
image2.Picture.Assign(myGif);
 
不行呀 我试过了 图片是经过压缩的 如果那样就会报数据溢出错误
 
TBlobField(ADOQuery1.FieldByName('SDImage')).SaveToStream(imgSeal);
//读取数据到流中
imgSeal.ReadBuffer(Count, SizeOf(Count));
//不懂干嘛用
GetMem(Buffer, Count);
//分配缓存
SourceStream:= TMemoryStream.Create;
//创建流
SourceStream.WriteBuffer(Buffer^, Count);
//缓冲BUFFER中并无数据,写入什么?
//这里就肯定会有错误,以下的操作没依据的了
DestStream.Position := 0;//复位流指针
DestStream.WriteBuffer(Buffer^, Count);
myGif.LoadFromStream(DestStream);
image2.Picture.Assign(myGif);
 
怎么改呢
 
后退
顶部