图像是bmp,橄榄色透明。
type
TForm1 = class(TForm)
ImageList: TImageList; //
MainMenu: TMainMenu; //Standart parameters
MenuItem: TMenuItem; //
procedure FormCreate(Sender: TObject);
...
function ScaleImage(aImage: TBitmap): TBitmap;
var
Src, Dst: TBitmap32;
R: TKernelResampler;
begin
Src := TBitmap32.Create;
Src.SetSize(16, 16);
Src.DrawMode := dmTransparent;
Src.OuterColor := clOlive;
Src.Assign(aImage);
Dst := TBitmap32.Create;
Dst.SetSize(24,24);
R := TKernelResampler.Create(Src);
R.Kernel := TLanczosKernel.Create;
Dst.DrawMode := dmTransparent;
Dst.OuterColor := clOlive;
Dst.Draw(Dst.BoundsRect, Src.BoundsRect, Src);
Result.Assign(Dst);
end;
procedure AddImage;
var
Image: TBitmap;
begin
Image := TBitmap.Create;
Image.LoadFromResourceName(hInstance, 'BMPNOFILTER');
ImageList.AddMasked(ScaleImage(Image), clOlive);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
AddImage;
MainMenu.Images := ImageList;
MenuItem.ImageIndex := 0;
end;
使用TBitmap
将结果TImageList
添加到图像列表Imagelist.AddMasked(Result, clOlive);
后,但图片会以橄榄色绘制。
尝试在没有橄榄色(aImage.transparent := True;
)的情况下调整图像大小,在指定Src背景变为黑色并将其用作透明色后,忽略OuterColor
值。
尝试将clOlive32作为OuterColor
。结果:
我使用的代码:
var
R: TKernelResampler;
Src, Dst: TBitmap32;
fImage: TBitmap;
OriginalImage, TranOriginalImage: TImage //16x16
SrcImage, DstImage, ResultImage: TImage //24x24
...
fImage := TBitmap.Create;
fImage.LoadFromResourceName(hInstance, 'BMPNOFILTER');
OriginalImage.Picture.Bitmap := fImage;
fImage.Transparent := True;
fImage.TransparentColor := clOlive;
TranOriginalImage.Picture.Bitmap := fImage;
TranOriginalImage.Transparent := True;
Src := TBitmap32.Create;
Src.SetSize(16, 16);
Src.OuterColor := clOlive32;
Src.Assign(fImage);
Src.DrawMode := dmTransparent;
Src.OuterColor := clOlive32;
SrcImage.Picture.Bitmap.Assign(Src);
Dst := TBitmap32.Create;
Dst.SetSize(24, 24);
Dst.DrawMode := dmTransparent;
Dst.OuterColor := clOlive32;
R := TKernelResampler.Create(Src);
R.Kernel := TLanczosKernel.Create;
Dst.Draw(Dst.BoundsRect, Src.BoundsRect, Src);
DstImage.Picture.Bitmap.Assign(Dst);
ResultImage.Picture.Bitmap.Assign(Dst);
ResultImage.Transparent := True;
答案 0 :(得分:0)
你应该使用Graphics32吊坠橄榄色。这是clOlive32而不是clOlive。随着添加
aImage.transparent := True;
这应该或多或少地发挥作用。
最终你会看到一些小故障,因为重新采样器可能不会将红色保留为红色,而是使用实际重新采样来获取边缘之间的颜色。