圖像是橄欖色透明顏色bmp。如何在graphisc32中正確調整透明圖像的大小?
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
後的ImageList TImageList
與Imagelist.AddMasked(Result, clOlive);
但圖像繪製用橄欖油顏色。 試圖調整圖像沒有橄欖色的顏色(aImage.transparent := True;
),分配後Src背景變成黑色並將其用作透明色,忽略OuterColor
值。
Tryed clOlive32 as 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;
你能顯示真實的代碼嗎?例如,我們不能說出Src,Dst,aImage是參數,全局變量,本地變量還是對象成員。請給我們一個小的,可編輯的程序來顯示你的問題。 – Dsm
我更新了代碼。 – Andrey
可以[這個問題](https://stackoverflow.com/a/32269633/5043424)幫助你嗎? –