老
老人头
Unregistered / Unconfirmed
GUEST, unregistred user!
delphi +sql server2000 怎样存储(保存+显示)图片啊? 急呀!
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, StdCtrls, ExtCtrls, DBCtrls, Grids, DBGrids, DB,JPEG;
type
TForm1 = class(TForm)
Table1: TTable;
Image1: TImage;
Button1: TButton;
Button2: TButton;
DataSource1: TDataSource;
OpenDialog1: TOpenDialog;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
FDataLink:TFieldDataLink
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
opendialog1.Execute;
image1.Picture.LoadFromFile(opendialog1.filename);
end;
procedure TForm1.Button2Click(Sender: TObject);
var
MyJPEG : TJPEGImage;
MS: TMemoryStream;
begin
MyJPEG := TJPEGImage.Create;
try
with MyJPEG do
begin
Assign(Image1.Picture.Graphic);
MS:=TMemoryStream.create;
SaveToStream(MS);
MS.Position:=0;
Table1.Edit;
TBlobField(Table1.FieldbyName('tu')).LoadFromStream(MS);
Table1.Post;
end;
finally
MyJPEG.Free;
end;
end;
end.
///////////////////////////////////////
procedure TDBImage.LoadPicture;
type TGraphicFmt=(gfUnKnown,gfBitmap,gfJpg);
var BlobStrm: TStream;
GraphicFmt: TGraphicFmt;
procedure getGraphicClass;
var b1,b2,b3: Byte;
begin
//Bmp:42 4d Jpg:FF D8 Gif: 47 49 46 wmf: D7 CD Ico:00 00 01
BlobStrm.Seek(0,0);
BlobStrm.Read(B1,1);
BlobStrm.Read(B2,1);
BlobStrm.Read(B3,1);
GraphicFmt:=gfUnknown;
if (B1=$42) and (B2=$4d) then GraphicFmt:=gfBitmap
else if (B1=$FF) and (B2=$D8) then GraphicFmt:=gfJpg;
end;
begin
if not FPictureLoaded and (not Assigned(FDataLink.Field) or
FDataLink.Field.IsBlob) then
// Picture.Assign(FDataLink.Field);
begin
if Assigned(FDataLink.Field) and(not FDataLink.Field.IsNull) then
begin
BlobStrm:=FDataLink.DataSet.CreateBlobStream(FDataLink.Field, bmRead);
try
GraphicFmt:=gfUnknown;
if BlobStrm.Size > 10 then getGraphicClass;
case GraphicFmt of
gfJpg:begin
if (Picture.Graphic=nil)or(not (Picture.Graphic is TJpegImage)) then
begin
if Picture.Graphic<>nil then Picture.Graphic.Free;
Picture.Graphic:=TJpegImage.Create;
end;
end;
gfBitmap:begin
if (Picture.Graphic=nil)or(not (Picture.Graphic is TBitmap)) then
begin
if Picture.Graphic<>nil then Picture.Graphic.Free;
Picture.Graphic:=TBitmap.Create;
end;
end;
else begin
if Picture.Graphic<>nil then Picture.Graphic.Free;
Picture.Graphic:=nil;
end;
end;
if Picture.Graphic<>nil then
begin
BlobStrm.Seek(0,0);
Picture.Graphic.LoadFromStream(BlobStrm);
end else Paint;
finally
BlobStrm.Free;
end;
end
else Picture.Bitmap.Assign(nil);
end;
end;
procedure TDBImage.UpdateData(Sender: TObject);
var BlobStrm: TStream;
begin
//if Picture.Graphic is TBitmap then
// FDataLink.Field.Assign(Picture.Graphic) else
if Picture.Graphic<>nil then
begin
BlobStrm := FDataLink.DataSet.CreateBlobStream(FDataLink.Field, bmWrite);
try
Picture.Graphic.SaveToStream(BlobStrm);
finally
BlobStrm.Free;
end;
end else
FDataLink.Field.Clear;
end;
请问在装jpg图象时,它为何会提示
BITMAP IMAGE IS NOT VALID?
麻烦您们帮我看一下啦!!!
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, StdCtrls, ExtCtrls, DBCtrls, Grids, DBGrids, DB,JPEG;
type
TForm1 = class(TForm)
Table1: TTable;
Image1: TImage;
Button1: TButton;
Button2: TButton;
DataSource1: TDataSource;
OpenDialog1: TOpenDialog;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
FDataLink:TFieldDataLink
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
opendialog1.Execute;
image1.Picture.LoadFromFile(opendialog1.filename);
end;
procedure TForm1.Button2Click(Sender: TObject);
var
MyJPEG : TJPEGImage;
MS: TMemoryStream;
begin
MyJPEG := TJPEGImage.Create;
try
with MyJPEG do
begin
Assign(Image1.Picture.Graphic);
MS:=TMemoryStream.create;
SaveToStream(MS);
MS.Position:=0;
Table1.Edit;
TBlobField(Table1.FieldbyName('tu')).LoadFromStream(MS);
Table1.Post;
end;
finally
MyJPEG.Free;
end;
end;
end.
///////////////////////////////////////
procedure TDBImage.LoadPicture;
type TGraphicFmt=(gfUnKnown,gfBitmap,gfJpg);
var BlobStrm: TStream;
GraphicFmt: TGraphicFmt;
procedure getGraphicClass;
var b1,b2,b3: Byte;
begin
//Bmp:42 4d Jpg:FF D8 Gif: 47 49 46 wmf: D7 CD Ico:00 00 01
BlobStrm.Seek(0,0);
BlobStrm.Read(B1,1);
BlobStrm.Read(B2,1);
BlobStrm.Read(B3,1);
GraphicFmt:=gfUnknown;
if (B1=$42) and (B2=$4d) then GraphicFmt:=gfBitmap
else if (B1=$FF) and (B2=$D8) then GraphicFmt:=gfJpg;
end;
begin
if not FPictureLoaded and (not Assigned(FDataLink.Field) or
FDataLink.Field.IsBlob) then
// Picture.Assign(FDataLink.Field);
begin
if Assigned(FDataLink.Field) and(not FDataLink.Field.IsNull) then
begin
BlobStrm:=FDataLink.DataSet.CreateBlobStream(FDataLink.Field, bmRead);
try
GraphicFmt:=gfUnknown;
if BlobStrm.Size > 10 then getGraphicClass;
case GraphicFmt of
gfJpg:begin
if (Picture.Graphic=nil)or(not (Picture.Graphic is TJpegImage)) then
begin
if Picture.Graphic<>nil then Picture.Graphic.Free;
Picture.Graphic:=TJpegImage.Create;
end;
end;
gfBitmap:begin
if (Picture.Graphic=nil)or(not (Picture.Graphic is TBitmap)) then
begin
if Picture.Graphic<>nil then Picture.Graphic.Free;
Picture.Graphic:=TBitmap.Create;
end;
end;
else begin
if Picture.Graphic<>nil then Picture.Graphic.Free;
Picture.Graphic:=nil;
end;
end;
if Picture.Graphic<>nil then
begin
BlobStrm.Seek(0,0);
Picture.Graphic.LoadFromStream(BlobStrm);
end else Paint;
finally
BlobStrm.Free;
end;
end
else Picture.Bitmap.Assign(nil);
end;
end;
procedure TDBImage.UpdateData(Sender: TObject);
var BlobStrm: TStream;
begin
//if Picture.Graphic is TBitmap then
// FDataLink.Field.Assign(Picture.Graphic) else
if Picture.Graphic<>nil then
begin
BlobStrm := FDataLink.DataSet.CreateBlobStream(FDataLink.Field, bmWrite);
try
Picture.Graphic.SaveToStream(BlobStrm);
finally
BlobStrm.Free;
end;
end else
FDataLink.Field.Clear;
end;
请问在装jpg图象时,它为何会提示
BITMAP IMAGE IS NOT VALID?
麻烦您们帮我看一下啦!!!