Transparent PNG image (with TImageList) in a TMainMenu - delphi

I want to load a PNG with transparent background in a TImageList and use it in a TMainMenu (via TAction).
However, in Delphi the background is just black.
This guy says it worked for him, but with a button instead of a main menu.
My setup:
My image is 8 bit per color plus 8 bit for transparency channel (I have tried also with 1 bit for transparency but still doesn't work). The image looks just fine in any other program.
Delphi XE.
In TImageList's editor, the 'transparent color' and 'Fill color' are set to 'Default' and are disabled.

There's no reason to backup whole DFM file.
Before doing something to your ImageList you should export your images: click the "Export" button in the image list editor and it will save all images to a single .BMP file.
After changing properties: ColorDepth = cd32Bit, DrawingStyle = dsTransparent
You should click "Add" button and select the file you previously exported. Then, images will be drawn with transparency in the menu and toolbars (on D2010 at least)... No need to use 3rd party components.

Set the following property values for TImageList:
DrawingStyle: dsTransparent
ColorDepth: cd32Bit
TImageList's editor -> set the 'transparent color' to True
In "Project Settings" under "Application" set "Enable runtime themes".
Update for Delphi Rio:
TImageList must have:
BkGColor = clNone
BlendColor = clNone,
ColorDepth = cd32bit,
DrawingStyle = dsTransparent (or) dsNormal,
Masked = true.
The images can be loaded from a PNG with transparent bkg color.
Note: Editing some properties of TImageList will delete (without any notice) all existing images in your list. Backup your images (or DFM) first.

I had been using TPngComponents since Delphi 7. That provide very good png support for most of the delphi build-in / third party components. Embarcadero had purchased another well know Open Sources PNG Supporting component know as TPngImage and build into Delphi's native graphic support in later Delphi versions. So when I changed to Delphi 2010, I think Delphi had native support now and test out the native support but find that the alpha support is not good enough.
So I had used back that TPngComponents again and it had better support for most components, including main menu. I think that package should be usable to DXE with limited modification.
edit : Thanks for Uwe Raabe for pointing out the product Codegear (now Embarcadero) purchased was another component TPngImage rather then the TPngComponent.

Related

DELPHI - PNG Images in TPageControl

In my Delphi XE3 Application I've placed a TPageControl component into the MainForm.
I linked its "Images" property to a ImageList which contains some PNG images.
At design time when I set the "Image Index" properties of each TTabSheet the images are correctly represented. Otherwise, when I run the application I see that all the images contained in the TTabSheet (which should be without background) are surrounded by a black squared area.
I check the settings of my ImageList and I see that:
-BkColor: clNone
-BlendColor: clNone
-ColorDepth: cd32bit
-DrawingStyle: dsTransparent
-ImageType: itImage
-Masked: False
I don't know whether it will be relevant to the problem but I note that changing the settings of the Project and enabling the voice "Enable runtime theme" this problem is solved.
Thanks.

A button control and underlying replacement for TBitmap that properly handles PNG transparency without writing pre-blend code

Delphi 2010's TSpeedButtons did not seem to really support PNG transparency properly, because the Glyph property uses a TBitmap internally, and TBitmap is for bitmaps, and doesn't support PNG transparency properly, and TSpeedButton.Glyph can't support transparency then.. update: But the actual problem was that I had some external stuff (Developer Express components) that was rendering delphi's PNG support non-functional, TImage on the other hand, while it still TPicture, and can support PNG, was also affected by this Developer express bug.
A question was already asked about here, and the answer shows how to use pre-blending so that transparency won't turn into black pixels. I want to know if there is another button control that will use alpha-blended PNGs loaded at designtime, and which does not convert the PNG resources into BMP format discarding the alpha channel and, causing the black border shown here.
In short, this control would not use TBitmap, and would not use the color key transparency feature that is all TBitmap has.
To repeat, I am not asking how to solve the black-around-the-outside issue while still using the out-of-date TBitmap/TSpeedButton based VCL functionality, because it lacks modern PNG transparency functionality, I am asking about replacing it with something else that "just works".
As a secondary drawback, converting a small .png file into a .DFM bitmap resource is essentially wasting space and making my form .DFM content too large. Native .png file format storage within the .dfm should make the resulting forms smaller.
Update: PngComponents look like they should work, but I got an Invalid Graphic format error when I try to load a png into the Png speedbutton. Note that the Png image list component has no such problems. It seems that cxLibrary (a developer express package) is breaking things. Once I removed all developer express stuff, this problem goes away. So although I have selected Pngcomponents as the answer, if you have devex stuff installed, use their buttons instead, and not pngcomponents.
You may have a look at PngComponents. It has a TPngSpeedbutton and some other controls working directly with PngImages.
You could also look into the TMS Software Component called TAdvGlowButton as this supports PNG images with alpha transparency.
Link to site...
It turns out that cxButton that comes in the Developer Express VCL component pack also supports PNG buttons.

Problem changing icon in Delphi 2007

I've been working with a program someone else has made and I wanted to change the icon.
The icon I have is 256x256. I used http://converticon.com/ to create the icon (from a bmp I think). I used the icon in Inno Setup to create an installer and it worked fine
So I go to Options -> Application and attempt to load it. However, Delphi 2007 gives me an error 'The parameter is incorrect.' with this info: http://i.stack.imgur.com/vRCgs.png
When I do the same thing in Delphi XE, it works and loads the icon and changes it on compile. I can't use XE right now because the program uses a math parser that has a problem with unicode (thats something to fix for later haha)
So, what I did was open the project in XE, change the icon, save it, delete the dproj and open it in 2007. This works, compiles and displays the correct icon, but when I go to the project options, it gives me the same 'The parameter is incorrect' error.
The workaround isn't a big deal, but I shouldn't need to do it. Does anyone know why I can't change the icon in Delphi 2007?
Edit: I just used that same converticon site to convert the 256x256 icon to 192x192 and smaller and now it works perfectly. Thanks for the answers
The "icon" file is actually a collection of images, at different resolution and using different encodings. When I'm creating my icons I'm making sure they don't actually contain the 256x256 PNG-encoded version because development tools built before Windows Vista don't understand that. And that includes your Delphi 2007 and my Delphi 7. I also remove the alpha-encoded 256x256 icon because it simply makes the file needlessly large.
You've got two fixes possible:
Find an ICO editor and remove all of the larger formats until your Delphi accepts the icon. I personally never seen the 256x256 used in the real world, they'd take up huge amounts of space on user's Desktop or in Windows Explorer.
Use a dummy icon and replace the icon resource in the generated exe after Delphi is done with it. This way you can keep all of the larger image formats, including the 256x256 PNG image.
Edit to correct an error
If possible, always include the 256x256 image, Windows scales that down for everything above 64x64.
I always assumed Windows Explorer would show an image that's based on the closest matching image size available in the ICO. That is, if a 128x128 image is necessary, Windows would use the 128x128 image if available, or scale down the 256x256 image if that's available, or scale up the 96x96 image. Apparently that's not so. I've just made a test icon consisting of several image formats, including 32, 48, 72, 96, 128 and 256 consisting of simple blobs of color (using the flood-fill tool). In Windows Explorer I cycled throw the various Display Modes, and it became apparent that starting with "Large Icon" (and that's not very large) Windows will scale down the 256x256 icon, and if that's not available, use the 48x48 icon, unscaled! The result is truly ugly and unexpected. The 72x72, 96x96 and 128x128 icons were simply ignored.
Thank you David for pointing this out.
Older versions of Delphi don't support 256px Vista icons. I believe that 2010 does not support them so I guess the limitation was fixed in XE.
When working with an older Delphi you'll need to keep the 256px icon out of the IDE. You can still build an executable with a 256px icon from the command line compiler - I used to do just this before upgrading from Delphi 6. But to do this requires the use of a competent resource compiler, for example the Microsoft one.
2007 will let you select icons with a 256 pixel image. Here is what I tried:
The default icon for Delphi XE contains several image sizes, including a 256 pixel image.
If I extract the icon from a Delphi XE application using a resource editor, I can add that icon to a Delphi 2007 application using the IDE's project options. I don't get an error, and the icon images show as expected in Windows Vista/7 using Explorer at different sizes.
If I take the same icon that worked in Delphi 2007 and remove all of the image sizes other than the 256 pixel image using IcoFX, and try to select it again, then I get an error.
Try creating a .ico that includes other image sizes and see if that works for you.

Image as a background of a form in Delphi

I'm using Delphi 2006. I have a few PNG images with transparencies and I have to create a GUI using them (top bar, left panel...). The images have different aligns properties. One of the images is the background of the form. The problem here is that I can't align it as alClient because it only occupies the rectangular zone that the other images have left, showing the naked canvas in their transparent zones. What I need is that the background image is put behind all the other images and taking all the canvas size.
Is there anyway to do this? I know I can do this writting some logic in the OnResize event of the form but I was just curious if I was missing something.
Thanks.
Put a TImage on the form and align it with "alClient". Then put an "alClient" aligned Panel on the form. The TPanel is transparent when themes are enabled and "ParentBackground" property is set. Then put the images on the panel and align them at will. If when themes are not enabled is important, you can use a "TJvPanel" which is part of the JVCL library. A search on google also seems to reveal some code for transparent panels.
The above will not help transparency with the "png"s though. AFAIK png support (transparency) is added with D2009 and I don't know if this support includes TImage.
edit: Actually it appears that I owe the very capability to load png images to TImage to the JVCL library itself, and it seems to support transparent "png"s with TImage just fine.

Delphi 2009 Application using Large Icons for Vista

I want to use Vista Large Icon feature in my Delphi 2009 application, but I can only embed the normal 32x32 icon in my application. How can I make application have many sizes of Icons?
Thanks
Go download IcoFX. It's free and handles multiple sizes/colour depths AND proper alpha blending. Use that to create your ICO file, then add the ICO to your project. Can't give you a blow-by-blow of the steps for loading the ICO in 2009, because I'm stuck using Delphi 7...
If it's any consolation, Visual Studio has taken eons to get anywhere near decent icon editing too.
Hey, who remembers the Borland Resource Workshop ?
I would use a icon editor such as AWIcons which allows you to create an icon that contains many different formats. Windows will then decide, based on the current view and color depth, which icon to use.
Once you have created your SINGLE icon with many different embedded formats, just link it like you would your 32x32 icon. It might look funny in the IDE, but when you run the program it will look correctly.
Get a decent stock of icons, or make your own. I use an the icon library from Icon Experience - your pay, but all icon sizes 16x16 up to 256 x 256 are provided in ICO and PNG formats. I then use Icon Sushi to work with my own icons. Delphi 7 and 2009 both have limitations working with large icons, so I've moved to using PNG icons using the PNG components library. This gives you a TPNGImageList that just works where the Vista cacheing and other problems make using TImageList only really good for 16x16 and 32x32 sizes. I've also ported PNGComponents to D2009 where it works fine.
Brian
I can only embed the normal 32x32 icon
in my application
From my experience, Delphi 2009 lets you use any icon. I've used extra large Vista icons too, and it worked.
Solution:
There is a BETTER AND EASY way to add high resolution icons in your Delphi 7 application.
It doesn't involve hacking your exe file:
http://thesunstroke.blogspot.com/2010/10/how-to-add-high-resolution-icons-to.html
If your are wanting some free software to create icons then you can probably use GIMP. My very first video tutorial was using GIMP to create icons - it's available here.
Configure the project to use the Microsoft resource compiler.
Once you are done building your project, add all the needed icons your project needs at the post-build step with the resource editor as described here: http://www.heaventools.com/rtconsole-sample-script-guide.htm

Resources