Solved

Add transparent PNG to TImageList at runtime in Delphi 2009

Posted on 2009-05-03
8
4,851 Views
Last Modified: 2013-11-23
Hi!

I'd like to add a RGB/8bit/Alpha PNG to a TImageList at runtime in Delphi 2009. I really can't find a decent way to do this, however you can add PNGs at design time with built in editor.

And still there is a problem if you add a transparent PNG at designtime ... transparency is not working fine ... it is just a black background (on Main menu for example).

Thanks for helping me with this one.
0
Comment
Question by:DKropf3
  • 4
  • 4
8 Comments
 

Author Comment

by:DKropf3
Comment Utility
Ok, one step forward i made ... (still can't add png at runtime) but if i add png at design time and set TImageList's ColorDepth to cd32Bit it works with mainmenu ... but not with speedbutton.
exit.bmp
0
 

Author Comment

by:DKropf3
Comment Utility
Ok almost solved by me ... will still grant 500 points to the one solving problem with TBitBtn and TSpeedButton.

See picture below ...

Solution for:
1. TimageList runtime add PNG with alpha:
---
ImageList.ColorDepth:=cd32Bit;
...
aPNG:=TPNGImage.Create;
try
 aPNG.loadfromfile('test.png');

    aBMP:=TBitmap.Create;
    try
     aBMP.Assign(aPNG);
     ImageList.Add(aBMP, nil);
    finally
     aBMP.Free;
    end;

finally
 aPNG.Free;
end;
---

Works with TMainMenu ---

the same stuf does not work with
tbitbutton and tspeedbutton

i tried:
   SpeedButton1.Glyph:=TBitmap.Create;
   SpeedButton1.Glyph.PixelFormat:=pf32Bit;
   and assign aPNG like above but result is in folowing picture ...

Please solve this ...

exit2.bmp
0
 
LVL 2

Accepted Solution

by:
Morris_Szyslak earned 500 total points
Comment Utility
Try using a TAction, TActionList resp.
Reference your ImageList to ActionList.Images.
Create an Action and define the ImageIndex, and reference the Action in your SpeedButtons and BitButtons. You can also use the Action for your menu Items, but you have to reference the ImageList in the MainMenu.Images. The Glyphs and Methods are all handled by the Action. This works great for me.
0
 

Author Comment

by:DKropf3
Comment Utility
Thanks Morris - your comment resulted in step forward to solution ...

I think before Alpha was completely lost ... now (purple ... see below) is not lost - it's there - but it is ignored .... :)

What now? And why it is ok on mainmenu ...

exit3.bmp
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 2

Assisted Solution

by:Morris_Szyslak
Morris_Szyslak earned 500 total points
Comment Utility
It looks like there are two colors around the actual glyphs. The outer color is used as transparent color, the inner color is displayed. Maybe this is an effect of the format conversion from png to bitmap or a scaling effect. Is the glyph of the same size as the ImageList?

Some things that are interesting to know:
Is it the same when you add the png at design time?
How does the glyph look in the image list editor?
Do you use the same image list for the main menu and for the buttons/actions?
0
 

Author Comment

by:DKropf3
Comment Utility
Morris,

that color around the glyph is alpha transparency in .png image. I use the same imgelist for mainmenu and actionlist. It is the same if i add it designtime or runtime.

Still ok on mainmenu or if i copy it from ImageList to TImage.

exit4.bmp
cancel-16.png
0
 
LVL 2

Assisted Solution

by:Morris_Szyslak
Morris_Szyslak earned 500 total points
Comment Utility
TBitButton and TSpeedButton seem to have problems with alpha blending. The "old" transparency with selecting a certain color as transparent color does work however. Therefore the outer area where alpha is 100% transparent is chosen as transparent color, the area directly around the image is partly transparent and doesn't match the transparent color and is painted.

You could either
-use glyphs without alpha transparency or
-try to find / develop a fix for TBitButton and / or TSpeedButton or
-use a component that works like TBitButton or TSpeedButton and can handle alpha.
0
 
LVL 2

Assisted Solution

by:Morris_Szyslak
Morris_Szyslak earned 500 total points
Comment Utility
Maybe you like a tool bar? Alpha seems to work there.
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Here is a helpful source code for C++ Builder programmers that allows you to manage and manipulate HTML content from C++ code, while also handling HTML events like onclick, onmouseover, ... Some objects defined and used in this source include: …
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org (http://seleniumhq.org) Go to that link and select download selenium in the right hand columnThat will then direct you to their downlo…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now