TJpegImage 與TBitMap的問題 |
答題得分者是:deity
|
johnny2212
初階會員 ![]() ![]() 發表:34 回覆:65 積分:39 註冊:2003-04-09 發送簡訊給我 |
|
deity
尊榮會員 ![]() ![]() ![]() ![]() ![]() ![]() 發表:90 回覆:876 積分:678 註冊:2003-05-09 發送簡訊給我 |
johnny2212 你好:
可参照讲解,很详细的说明
http://delphi.about.com/library/weekly/aa030601c.htm
unit Unit1; interface uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Buttons, ExtCtrls, StdCtrls, Db, ADODB, Grids, DBCtrls, DBGrids; type
TForm1 = class(TForm)
ADOTable1: TADOTable;
DataSource1: TDataSource;
btnShowImage: TButton;
ADOImage: TImage;
ADOTable1Name: TWideStringField;
ADOTable1Description: TWideStringField;
ADOTable1Author: TWideStringField;
ADOTable1Type: TWideStringField;
ADOTable1Size: TFloatField;
ADOTable1Cost: TBCDField;
ADOTable1DateUpl: TDateTimeField;
ADOTable1Picture: TBlobField;
DBGrid1: TDBGrid;
procedure btnShowImageClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end; const
JPEGstarts = 'FFD8';
BMPstarts = '424D'; //BM var
Form1: TForm1; implementation
uses jpeg;
{$R *.DFM} function JpegStartsInBlob (PicField:TBlobField):integer;
var
bS : TADOBlobStream;
buffer : Word;
hx : string;
begin
Result := -1;
bS := TADOBlobStream.Create(PicField, bmRead);
try
while (Result = -1) and (bS.Position 1 < bS.Size) do
begin
bS.ReadBuffer(buffer, 1);
hx:=IntToHex(buffer, 2);
if hx = 'FF' then begin
bS.ReadBuffer(buffer, 1);
hx:=IntToHex(buffer, 2);
if hx = 'D8' then Result := bS.Position - 2
else if hx = 'FF' then bS.Position := bS.Position-1;
end; //if
end; //while
finally
bS.Free
end; //try
end; procedure TForm1.btnShowImageClick(Sender: TObject);
var
bS : TADOBlobStream;
Pic : TJpegImage;
begin
bS := TADOBlobStream.Create(AdoTable1Picture, bmRead);
try
bS.Seek(JpegStartsInBlob(AdoTable1Picture), soFromBeginning);
Pic:=TJpegImage.Create;
try
Pic.LoadFromStream(bS);
ADOImage.Picture.Graphic:=Pic;
finally
Pic.Free;
end;
finally
bS.Free
end;
end; procedure TForm1.FormCreate(Sender: TObject);
var sDBPath, sCons: string;
begin
//change the sDBPath to point to your database!
sDBPath := 'c:\!Gajba\About\aboutdelphi.mdb';
sCons := 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=' sDBPath ';Persist Security Info=False'; ADOTable1.ConnectionString := sCons;
ADOTable1.TableName := 'Applications';
DataSource1.DataSet := ADOTable1;
DBGrid1.DataSource := DataSource1; ADOTable1.Active:=True;
end; procedure TForm1.FormDestroy(Sender: TObject);
begin
ADOTable1.Active:=False;
end; //Extra!! save JPG to table
procedure SaveJpegToTable(Table: TADOTable; PicField:TBlobField; sPicPath: string);
{
Usage: SPicFileName := 'C:\!gajba\cdcovers\cdcover1.jpg';
SaveJpegToTable(ADOTable1, ADOTable1Picture, SPicFileName);
}
var
fS : TFileStream;
begin
fs:=TFileStream.Create(sPicPath, fmOpenRead);
try
Table.Edit;
PicField.LoadFromStream(fs);
Table.Post;
finally
fs.Free;
end;
end; end.
——行径窄处,留一步与人行——
——Never give up, never surrender—— 發表人 - deity 於 2004/05/30 23:10:36
|
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |