用户登录  |  用户注册
首 页商业源码原创产品编程论坛
当前位置:PB创新网文章中心编程技巧Delphi

一个简单的显示和存放JPEG图形的控件

减小字体 增大字体 作者:佚名  来源:本站整理  发布时间:2009-03-16 20:19:39
很久以前写的,今天正好看到有人需要,就贴出来了。

unit JPGDBImage;

interface

uses Classes, DBCtrls, Controls, Graphics, JPEG, DB;

type
TJPGDBImage = class(TDBImage)
public
constructor Create(AOwner: TComponent); override;
end;

implementation

type
TGraphicHeader = record
Count: Word; { Fixed at 1 }
HType: Word; { Fixed at $0100 }
Size: Longint; { Size not including header }
end;

TDBPicture = class(TPicture)
public
procedure Assign(Source: TPersistent); override;
end;

{$HINTS OFF}
THackDBImage = class(TCustomControl)
private
FDataLink: TFieldDataLink;
FPicture: TPicture;
end;
{$HINTS ON}

procedure TDBPicture.Assign(Source: TPersistent);
var
BlobStream: TStream;
BMPTag: array [0..1] of Char;
AJPG: TJPEGImage;
Size, SavePos: Integer;
Header: TGraphicHeader;
begin
if (Source is TField) and (TField(Source).IsBlob) and not TField(Source).IsNull then
begin
BlobStream := TField(Source).DataSet.CreateBlobStream(TField(Source), bmRead);
try
Size := BlobStream.Size;
if Size >= SizeOf(TGraphicHeader) then
begin
BlobStream.Read(Header, SizeOf(Header));
if (Header.Count <> 1) or (Header.HType <> $0100) or
(Header.Size <> Size - SizeOf(Header)) then
BlobStream.Position := 0;
end;
SavePos := BlobStream.Position;
BlobStream.Read(BMPTag, 2);
BlobStream.Position := SavePos;
if (BMPTag[0] = ''B'') and (BMPTag[1] = ''M'') then
LoadFromStream(BlobStream)
else
begin
AJPG := TJPEGImage.Create;
try
AJPG.LoadFromStream(BlobStream);
inherited Assign(AJPG);
finally
AJPG.Free;
end;
end;
finally
BlobStream.Free;
end;
end
else
inherited;
end;

constructor TJPGDBImage.Create(AOwner: TComponent);
var
ADBPicture: TDBPicture;
begin
inherited;

ADBPicture := TDBPicture.Create;
ADBPicture.OnChange := THackDBImage(Self).FPicture.OnChange;
THackDBImage(Self).FPicture.Free;
THackDBImage(Self).FPicture := ADBPicture;
end;

end.

Tags:

作者:佚名

文章评论评论内容只代表网友观点,与本站立场无关!

   评论摘要(共 0 条,得分 0 分,平均 0 分) 查看完整评论
PB创新网ourmis.com】Copyright © 2000-2009 . All Rights Reserved .
页面执行时间:31,140.63000 毫秒
Email:ourmis@126.com QQ:2322888 蜀ICP备05006790号