0

Image is bmp with olive transparent color.

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;

After that result TBitmap to imagelist TImageList with Imagelist.AddMasked(Result, clOlive); but image is drawn with olive color. Trying to resize image without olive color (aImage.transparent := True;), after assign Src background become black and use it as transparent color, ignoring OuterColor value.

Tryed clOlive32 as OuterColor. Result:

Code i used:

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; 
Andrey
  • 65
  • 5
  • Can you please show real code? We cannot, for example, tell whether Src, Dst, aImage are parameters, globals, locals or object members, for instance. Please give us a small, compilable, program showing your problem. – Dsm Oct 11 '17 at 08:29
  • I updated code. – Andrey Oct 11 '17 at 08:55
  • Can [this question](https://stackoverflow.com/a/32269633/5043424) help you? – asd-tm Oct 11 '17 at 09:20
  • @asd-tm I tried `Src.DrawMode:=dmBlend` and `Src.DrawMode:=dmOpaque` with no result. Also tried to do the same for `Dst.DrawMode`. Black background after `Src.Assing(aImage)`. – Andrey Oct 11 '17 at 09:36
  • Note: The code is not 100% correct as it misses the creation of the Result TBitmap instance. – CWBudde Oct 12 '17 at 00:28

1 Answers1

0

You should use the Graphics32 pendant to the olive color. This is clOlive32 instead of clOlive. Along with adding

aImage.transparent := True;

this should do the trick more or less.

Eventually you will see a few glitches as the resampler might not preserve red as red, but use actual resampling to get colors in between around the edges.

CWBudde
  • 1,783
  • 1
  • 24
  • 28
  • Set clOlive32 on `Src.OuterColor` and `Dst.OuterColor`, set `Image.Transparent := True` before `Src.Assign(aImage)`. I will add new result in main post. – Andrey Oct 12 '17 at 07:57
  • Added image with result to main post. I think the problem is in the pixelformat of the original image. After loading its value pf4bit. Tried to save original image in pf32bit and all images had olive background. – Andrey Oct 12 '17 at 08:22