抱歉,我的英语不是很好。
我需要在我的 D7 应用程序中使用半透明位图图片。所以,我应该使用 XPManifest 和 ImageList version6 而不是 5.8 标准版。但在这种情况下,我遇到了一个问题:当我从流中加载图像时,所有图像都会失去透明度!
type
TForm2 = class(TForm)
btn4: TButton;
btn5: TButton;
lst1: TbtkListView;
il1: TImageList;
btn1: TButton;
tlb1: TToolBar;
btn2: TToolButton;
btn3: TToolButton;
xpmnfst1: TXPManifest;
procedure btn4Click(Sender: TObject);
procedure btn5Click(Sender: TObject);
procedure btn1Click(Sender: TObject);
private
FS: TFileStream;
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
implementation
{$R *.dfm}
procedure TForm2.btn4Click(Sender: TObject);
var
Bmp : TBitmap;
ImageList: TbtkImageList;
begin
ImageList := TbtkImageList.Create(nil);
Bmp := TBitmap.Create;
FS := TFileStream.Create('c:\temp\1.cmp',fmCreate);
try
Bmp.LoadFromFile('c:\temp\1.bmp');
ImageList.Add(Bmp, nil);
FS.WriteComponent(ImageList);
finally
Bmp.Free;
end;
end;
procedure TForm2.btn5Click(Sender: TObject);
var
Bmp : TBitmap;
ImageList : TbtkImageList;
begin
ImageList := TbtkImageList.Create(nil);
Bmp := TBitmap.Create;
try
FS.Position := 0;
FS.ReadComponent(ImageList);
ImageList.GetBitmap(0, Bmp);
Bmp.SaveToFile('c:\temp\3.bmp');
finally
Bmp.Free;
ImageList.Free;
end;
end;
ImageListCreationCode:
constructor TbtkImageList.Create(AOwner: TComponent);
begin
inherited;
if HandleAllocated then
ImageList_Destroy(Handle);
Handle := ImageList_Create(32, 32, ILC_COLOR32, AllocBy, AllocBy);
end;
http://s020.radikal.ru/i720/1403/36/c2702a8b5c1a.png http://s020.radikal.ru/i720/1403/36/c2702a8b5c1a.png Before
http://s001.radikal.ru/i195/1403/e2/1dd5ff14aa51.png http://s001.radikal.ru/i195/1403/e2/1dd5ff14aa51.png After
有人可以帮助我吗?
一旦您将具有 Alpha 通道信息的位图放入图像列表中,就没有简单的 (*) 方法可以将其以其原始位图形式取出。TImageList.GetBitmap
只需设置传递给它的位图的尺寸,并且draws在它的画布上。它不使用可以透明绘制的重载,但它并不那么重要,而不是使用GetBitmap
你可以打电话给Draw
让自己超负荷。
因此,如果您需要保留位图的原始形式,我建议不要对图像列表进行流式输入和输出,而是对位图本身进行流式传输。
尝试下面的方法,看看它是否符合您的需求(它是透明的,但可能与再次绘制的源位图不同):
var
Bmp : TBitmap;
ImageList : TImageList;
FS: TFileStream;
begin
ImageList := TImageList.Create(nil);
try
FS := TFileStream.Create('c:\temp\1.cmp',fmOpenRead or fmShareDenyWrite);
try
FS.ReadComponent(ImageList);
finally
FS.Free;
end;
Bmp := TBitmap.Create;
try
Bmp.PixelFormat := pf32bit;
Bmp.Canvas.Brush.Color := clNone;
Bmp.Width := ImageList.Width;
Bmp.Height := ImageList.Height;
ImageList.Draw(Bmp.Canvas, 0, 0, 0, dsNormal, itImage);
Bmp.SaveToFile('c:\temp\3.bmp');
finally
Bmp.Free;
end;
finally
ImageList.Free;
end;
end;
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)