如何在DBImage控件中显示jpeg格式或其它图像?(50分)

  • 主题发起人 主题发起人 kelf
  • 开始时间 开始时间
给你一个Jpg显示的例子,有这方面的控件,你再找找。
var
bmp1:Tbitmap;
jpg1:Tjpegimage;
begin
if OpenPictureDialog1.Execute then begin
if OpenPictureDialog1.FileName<>'' then begin
bmp1:=Tbitmap.Create;
jpg1:=Tjpegimage.Create;
jpg1.LoadFromFile(OpenPictureDialog1.filename);
bmp1.Assign(jpg1);
DataModule1.query1.edit;
DataModule1.query1.FieldByName('image').assign(bmp1);
DataModule1.query1.Post;
bmp1.free;
end;
end;
 
Dbimage是数据集控件,它所显示的是数据库中存储的图片。
存的什么格式的图片就显示什么样的图片。
 
ACCESS比较特殊
Would you believe this! MS Access stores the path of a linked OLE object as part of the object's definition in the OLE object field. Because the definition of OLE object storage is not documented (!? this is straight from MS) there is no way to know what gets written before the actual image data.

Think about this twice. First: we'll need to seek to the 'FFD8' and read the image from there. Second, the 'FFD8' might not always be at the same position in the file. Conclusion: we need a function that returns the position of the SOI marker for the JPG file stored as OLE object in an Access database.

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;

 
多人接受答案了。
 
后退
顶部