ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
Forum membership is Free!  Click Join to sign-up
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 How to get rid of the black background?
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

PeterPanino

993 Posts

Posted - Oct 15 2017 :  10:34:20  Show Profile  Reply
When assigning a 32x32 icon to a TImageEnView, I always get a black background:



This is how the icon looks in a native Windows dialog instead:



Please look at the attached Delphi example project: How can I display the icon in the ImageEnView with a transparent looking background?

attach/PeterPanino/20171015103258_ShowLargeExeIcon.zip
49.6 KB

w2m

USA
1990 Posts

Posted - Oct 15 2017 :  10:56:22  Show Profile  Reply
Just enable the alphachannel and set the transparent color:
procedure TForm2.ShowExeIcon(const AFile: string;
  const AIndex, AIconSize: Integer; AImage: TImageEnView);
var
  hIcon: THandle;
  nIconId: DWORD;
  Icon: TIcon;
  iRGB: TRGB;
begin
  if PrivateExtractIcons(PChar(AFile), AIndex, AIconSize, AIconSize, @hIcon,
    @nIconId, 1, LR_LOADFROMFILE) <> 0 then
  begin
    try
      Icon := TIcon.Create;
      try
        Icon.Handle := hIcon;
        AImage.Clear;
        AImage.Bitmap.Assign(Icon);
        AImage.EnableAlphaChannel := True;
        iRGB := AImage.IEBitmap.Pixels[0, AImage.IEBitmap.Height - 1];
        AImage.Proc.SetTransparentColors(iRGB, iRGB, 0);
        AImage.IO.Params.BitsPerSample := 8;
        AImage.IO.Params.SamplesPerPixel := 4;
        AImage.Update;
      finally
        Icon.Free;
      end;
    finally
      DestroyIcon(hIcon);
    end;
  end
  else
  begin
    //
  end;
end;

Bill Miller
Adirondack Software & Graphics
Email: w2m@hughes.net
EBook: http://www.imageen.com/ebook/
Custom Commercial ImageEn Development
Go to Top of Page

PeterPanino

993 Posts

Posted - Oct 15 2017 :  11:28:01  Show Profile  Reply
Thank you, Bill!

But why the image has such a dark border:



While the original icon has no border:



Use 74 as IconIndex this time:

ShowExeIcon('%systemroot%\system32\imageres.dll', 74, 32, _imgLargeIcon);


Isn't it possible to make the icon look as clean as the original icon image?
Go to Top of Page

w2m

USA
1990 Posts

Posted - Oct 15 2017 :  12:50:19  Show Profile  Reply
Take a look at the resource loader in the demos folder.

Bill Miller
Adirondack Software & Graphics
Email: w2m@hughes.net
EBook: http://www.imageen.com/ebook/
Custom Commercial ImageEn Development
Go to Top of Page

w2m

USA
1990 Posts

Posted - Oct 17 2017 :  09:07:05  Show Profile  Reply
I suspect you are getting incorrect result is because the icon frame you are loading is not 32-bit with alphachannel.

Bill Miller
Adirondack Software & Graphics
Email: w2m@hughes.net
EBook: http://www.imageen.com/ebook/
Custom Commercial ImageEn Development
Go to Top of Page

PeterPanino

993 Posts

Posted - Oct 19 2017 :  11:20:56  Show Profile  Reply
Bill, you are right.

I ended up using TImage. When I set Image.Transparent = false then the picture is perfect.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: