GDI+相关问题 ( 积分: 300 )

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

sortmail

Unregistered / Unconfirmed
GUEST, unregistred user!
代码如下
TPLButtonImages = class(TPersistent)
private
FUp: TGPImage;

FPicUp:TPicture;
protected
{ Property Access Methods }
procedure SetPicUp(Value:TPicture);
public
constructor Create;overload;
destructor Destroy; override;
published
{ Property Declarations }
property Up: TGPImage read FUp ;
property PicUp:TPicture read FPicUp write SetPicUp;

end;

{ TPLButtonImages }

constructor TPLButtonImages.Create;
begin
inherited;
FUp := TGPImage.Create;
FPicUp := TPicture.Create ;
end;

destructor TPLButtonImages.Destroy;
begin
FUp.Free ;
FPicUp.Free;
inherited;
end;

procedure TPLButtonImages.SetPicUp(Value: TPicture);
var
OLS:TOLEStream;
Stream:TStream;
ISt:IStream;
begin
//如何把TPicture类的FPicUp的图片给GDI+的FUp?
FPicUp.Assign(Value);
Stream := TStream.Create ;
FPicUp.Graphic.SaveToStream(Stream); //Graphics.saveToStream是个抽象类,这里行不通,不知如何写?
OLS := TOLEStream.Create(ISt);
OLS.CopyFrom(Stream,Stream.Size );
if FUp<>nil then
FUp.Free;
FUp := TGPImage.Create(ISt);
Stream.Free ;

end;
 
本意是写一个组件,用GDI+来画图,要用到一个图片是PNG的,装了PNG的一个包使TImage能显示和保存PNG图片到DFM文件中,但是却不知用GDI+如何取出来.TGPIamge.create(Stream:IStream)中的参数不知应如何取得
 
用TStreamAdapter代理IStream接下来就和正常Stream一样使用即可。
 
Rainstorey 非常感谢你的回复
我现在是不知如何从FPicUp里取出Stream出来,因为图片可能是PNG,BMP,JPEG格式
 
procedure TPLButtonImages.SetPicUp(Value: TPicture);
var
oBmp: TBitmap;
begin
FPicUp.Assign(Value);

oBmp := TBitmap.Create;
try
oBmp.Width := FPicUp.Graphic.Width;
oBmp.Height := FPicUp.Graphic.Height;
oBmp.Canvas.Draw(0, 0, FPicUp.Graphic);

FreeAndNil(FUp);
FUp := TGPBitmap.Create(oBmp.Handle, oBmp.Palette);
finally
oBmp.Free;
end;
end;

保您好用,有不明白的可以问我 QQ:9863231
 
多人接受答案了。
 
后退
顶部