图片存储的问题(100)

  • 主题发起人 主题发起人 shijies
  • 开始时间 开始时间
S

shijies

Unregistered / Unconfirmed
GUEST, unregistred user!
图片有jpeg和bmp等格式,往数据库里存储时,要先对图片分类吗?
 
最好要分类,或是标记,这样你读取时,图片处理的快。经验之谈。
 
就分成jpeg和bmp两类吗?写代码根据后缀去分?
 
可以通过Stream方式 下面有个相关操作的例子 unit Unit1; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,jpeg, ExtCtrls, StdCtrls,ActiveX, AxCtrls; type TForm1 = class(TForm) Image1: TImage; Button2: TButton; Image2: TImage; procedure Button2Click(Sender: TObject); private procedure StreamToVariant(Stream: TMemoryStream; var v: OleVariant); procedure VariantToStream(const v: olevariant; Stream: TMemoryStream); procedure JPEGToVariant(aJPEG : TJPEGImage; var aVariant:OleVariant); procedure VariantToJPEG(aValue : OleVariant; var aJPEG:TJPEGImage); { Private-Deklarationen } public { Public-Deklarationen } end; var Form1: TForm1; implementation {$R *.DFM} procedure TForm1.VariantToStream (const v : olevariant; Stream : TMemoryStream); var p : pointer; begin Stream.Position := 0; Stream.Size := VarArrayHighBound (v, 1) - VarArrayLowBound (v, 1) + 1; p := VarArrayLock (v); Stream.Write (p^, Stream.Size); VarArrayUnlock (v); Stream.Position := 0; end; procedure TForm1.StreamToVariant (Stream : TMemoryStream; var v : OleVariant); var p : pointer; begin v := VarArrayCreate ([0, Stream.Size - 1], varByte); p := VarArrayLock (v); Stream.Position := 0; Stream.Read (p^, Stream.Size); VarArrayUnlock (v); end; procedure TForm1.JPEGToVariant(aJPEG : TJPEGImage; var aVariant:OleVariant); var Stream : TMemoryStream; begin try Stream := TMemoryStream.Create; aJPEG.Assign(Image1.Picture.Bitmap); aJPEG.SaveToStream(Stream); StreamToVariant(Stream, aVariant); finally Stream.Free; end; end; procedure TForm1.VariantToJPEG(aValue : OleVariant;var aJPEG:TJPEGImage); var Stream : TMemoryStream; begin try Stream := TMemoryStream.Create; VariantToStream (aValue,Stream); aJPEG.LoadfromStream(Stream); finally VariantClear(aValue); Stream.free; end; end; procedure TForm1.Button2Click(Sender: TObject); var aJPEG :TJPEGImage; aVariant : OleVariant; begin try aJPEG:=TJPEGImage.Create; //JPEG To Variant aJPEG.Assign(Image1.Picture.Bitmap); JPEGToVariant(aJPEG,aVariant); //Variant To JPEG VariantToJPEG(aVariant,aJPEG); Image2.Picture.assign(aJPEG); finally aJPEG.free; end; end; end. Top2 楼ehom(?!)回复于 2002-07-20 02:28:32 得分 0 var ms:tmemorystream; jp:TJpegImage; begin ms:=tmemorystream.Create; jpeg:=TJpegImage.Create; try with ADOQuery1 do begin Open; First; TBlobField(FieldByName('img')).SaveToStream(ms); Close; end; ms.Position:=0; jpeg.LoadFromStream(ms); Image1.Picture.Bitmap.Assign(jpeg); finally ms.Free; jpeg.Free; end; end;
 
后退
顶部