如何成批地把圖片加入資料庫? |
答題得分者是:banson1716
|
bensonh
一般會員 發表:4 回覆:2 積分:1 註冊:2002-12-29 發送簡訊給我 |
|
banson1716
高階會員 發表:55 回覆:182 積分:167 註冊:2002-04-14 發送簡訊給我 |
程式 d5 調試
unit Unit1; interface uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs, Grids, DBGrids, DB, DBTables, DBCtrls, ExtDlgs, ExtCtrls,
StdCtrls; type
TForm1 = class(TForm)
Table1: TTable;
DataSource1: TDataSource;
DBGrid1: TDBGrid;
Table1NAME: TStringField;
Table1SIZE: TSmallintField;
Table1WEIGHT: TSmallintField;
Table1AREA: TStringField;
Table1BMP: TBlobField;
OpenPictureDialog1: TOpenPictureDialog;
Panel1: TPanel;
DBNavigator1: TDBNavigator;
Button1: TButton;
Panel2: TPanel;
Edit1: TEdit;
procedure FormCreate(Sender: TObject);
procedure DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect;
Field: TField; State: TGridDrawState);
procedure DBGrid1DblClick(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end; var
Form1: TForm1; implementation
Uses Jpeg;
{$R *.dfm} procedure TForm1.FormCreate(Sender: TObject);
begin
Table1.Close;
Table1.DatabaseName:='DBDEMOS';
Table1.TableName:='animals.dbf';
Table1.Open;
end; type
TGraphicHeader = record
Count: Word;
HType: Word;
Size: Longint;
end; procedure TForm1.DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect;
Field: TField; State: TGridDrawState);
Var BlobStream:TBlobStream;
BMP:TBitmap;
JPEGs:TJPEGImage;
JPEGStream:TMemoryStream;
Header:TGraphicHeader;
begin
if Field.IsBlob then
begin
if not Field.IsNull then
begin
BlobStream:=TBlobStream.Create(TBlobField(Field),bmRead);
try
BlobStream.Read(Header,Sizeof(TGraphicHeader));
//先讀一個流頭,這個流頭中記錄有圖片類型和圖片大小.
//對於BMP,TBlobField.Assign(方法會自動保存這個記錄,如果是JPG圖片,則需要編程去處理.)
if (Header.Count<>1) or (Header.Size<>(BlobStream.Size-SizeOf(Header))) then
DBGrid1.Canvas.TextOut(Rect.Left,Rect.Top,'
|
領航天使
站長 發表:12216 回覆:4186 積分:4084 註冊:2001-07-25 發送簡訊給我 |
|
banson1716
高階會員 發表:55 回覆:182 積分:167 註冊:2002-04-14 發送簡訊給我 |
VAR I :INTEGER;
begin
if OpenPictureDialog1.Execute then
begin
for i:=0 to OpenPictureDialog1.Files.count-1 do
begin
ADOTable1.append;
ADOTable1.FieldByName('IMG_FILENAME').AsString:=
Extractfilename(OpenPictureDialog1.Files[i]);
ADOTable1.FieldByName('IMG_FILESIZE').AsInteger:=
filesizes(OpenPictureDialog1.Files[i]);
TBlobField(ADOTable1.FieldByName('IMG_FILEDATA')).loadfromfile(OpenPictureDialog1.Files[i]);
ADOTable1.post;
ADOTable1AfterScroll(ADOTable1);
end;
END;
引言: 請參考站長寫的範例程式,將大型圖檔存入資料庫的示範程式: http://delphi.ktop.com.tw/topic.php?TOPIC_ID=19505 ~~~Delphi K.Top討論區站長~~~ |
banson1716
高階會員 發表:55 回覆:182 積分:167 註冊:2002-04-14 發送簡訊給我 |
|
bensonh
一般會員 發表:4 回覆:2 積分:1 註冊:2002-12-29 發送簡訊給我 |
|
bensonh
一般會員 發表:4 回覆:2 積分:1 註冊:2002-12-29 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |