Delphi: TPicture from TImageList - delphi

How to get a TPicture from a TImageList?
I need to do Image1.Picture:=...TPicture from an image list, to load an image into a TImage.
An image list stores all my PNG images that are transparent.
I tried to use a bitmap (GetBitmap), but what I need is transparency. Unfortunatelly, I have a white background using a bitmap.
Thanks!

The regular TImageList uses bitmaps. Although they can be partially transparent, it is actually just a fake. In Delphi you can draw bitmaps to be transparent by assigning them a single transparent color. That exact color will be drawn a 100% transparent, while the other colors are not. Usually the color is taken from the bottom left corner of the image.
TPicture itself doesn't do anything. It is merely a container for TGraphic descendants. You'll have to find a type of image that can be transparent.
A convenient format is PNG. PNG event supports an alpha channel, which means that every pixel can be assigned a different transparency value.
Fortunately there are TPngImageLists that combine the ease of TImageList with the power of PNG. You can read this article. It is in Dutch, but maybe Google Translate can help you. Or maybe you can find an english resource on this subject. I've used this imagelist and it's great, because you can have actual icons with an alpha channel and still use them with regular toolbars and speedbuttons.

Related

Delphi 2007 - Loading TJvImage from a PNG file loses transparency

I have a couple of TJvImage components on my main form. One is loaded at design time from a partially transparent PNG file. The other is smaller than the first and in front of it. It is loaded at runtime with another partially transparent PNG file.
JvImage1.Picture.LoadFromFile ('Logo.png') ;
JvImage1.Transparent is set to TRUE. The problem is simple: the smaller image is rendered ignoring the alpha channel - i.e. it punches out the background image.
This does not occur when I load both images at design-time. They both show as partially transparent on the form, and display correctly when I run the program.
The real dilemma is that a minimal test program written to try to demonstrate the problem does not show the problem, but the same code in the application proper doesn't behave.
Is there anything about the underlying main form that could affect the behaviour?
I don't know if this is the same for TJvImage but when you set Transparent property of TImage to True it causes TImage to skip rendering any pixel with TransparentColor.
If no transparent color is set the color of lower left pixel is used.
When in such mode TImage doesen't take into accound alpha channel. Infact Transparency only works when you load TBitmap typed image into TImage.
I gues that TJvImage probably works in similar way. So in order to show your image properly you should set the Transparent property to False. This will probably alow TJvImage to render your picture by using Alpha transparency that is encoded to the picture itself.

Delphi - Resize PNG with transparence and index

I have many PNG files with transparency and these PNG fiels seem to be indexed.
I would like to :
Put 2 identical PNG side to side with a space between both
Resize the result with a smooth resize filter (or Mitchell, Linear, Spline or other)
Keep transparency and originals colors
Do you have an example to do that ?
This question is related to other PNG resize questions but...
AFAIK, You can't resize an indexed image and keep the original palette. Resizing the image will necessitate the mixing of colors, especially in reducing the image.
The original author of the PNGImage component (the basis of the Delphi native component) had a forum where he, and others, posted code snippets on how to do things using the PNGImage component.
Before the forum was taken down I grabbed a copy of all of the code snippets and placed them on the CodeGear Code Central website.
Most if not all of these work with native PNG images and do maintain the Alpha channel.
Here is the complete list of examples included in the package:
Smooth rotates a PNG object
Resizes a TPNGObject using a smooth algorithm
Slice one PNG into several smaller ones
Saves an image as either a bitmap or a png.
Sample chunk descendant
Read all tEXt-Chunks and write values into a TStrings object
Display a message box with information extracted from the PNG File
Finds and cuts a block from a PNG image
This method converts the png into a jpeg object
This method converts the png into a bmp object
Overlay one PNG over another (This makes the image half transparent)
Flips a png image vertically and saves back
Draws a png image over the desktop
Here is the link: CodeCentral PNG Methods

Delphi TImageList PNG alpha renders too dark

I have PNG icons for my Delphi XE3 application toolbar that, when added to a TActionToolbar via a TImageList, the alpha channel renders darker than it should, causing the icons to look bad. I think the issue has to do with the TImageList and not something specifically with the TActionToolbar.
Photoshop mockup:
Actual look after importing to TActionToolbar (alpha is darker blue for the folder fill):
Here are my Delphi Object Inspector settings for the TImageList (no, the issue is not the BlendColor property):
Is there a way to get Delphi/Windows/whoever the culprit is to render the alpha channel properly? An option is to make the icons all bitmaps, but I'd rather not go through the headache of editing bitmaps with a transparent color because, well, I'd rather not revert to the days of the dinosaurs... TIA.
The best way I found to deal with this is to paint the background color of your Delphi toolbar (or whatever UI element) underneath every pixel that contains transparency in Photoshop before saving the PNG image. This way, the toolbar icons are totally opaque except for the 100% transparent pixels, so there is no alpha blending that takes place--and hence no ugliness.
Use RRUZ's code here to make the disabled toolbar icons look better.

Drawing a PNG Graphic to a Canvas without transparency?

I've seen many questions asking how to draw transparent images, but my case is quite the opposite. I have a TPicture where I load any file type, including PNG. I then read TPicture.Graphic and call Draw directly in a TBitmap's canvas. However, when the image is drawn, it carries over the transparency of the original PNG image.
The current code is very simple, just...
MyPicture.LoadFromFile(SomeFilename);
MyBitmap.Canvas.StretchDraw(SomeRect, MyPicture.Graphic);
Now the issue is that the canvas which I'm drawing to already has an image, and this PNG is being drawn over a portion of it. When the PNG has a transparent background, normally it appears white. However, since it's directly drawing a transparent graphic to the canvas, it keeps those areas transparent.
How can I draw a PNG Graphic directly to a canvas without its original transparency while using only the canvas drawing methods? I don't want to create too many graphic objects and draw too many times, hence the reason I only have 2 lines of code above. I'm hoping there's a way I can do something like BitBlt with some special mechanism for this purpose.
The only method pre-built in Delphi XE2 has a defect and doesn't work properly. Instead, draw whitespace, or whatever background you desire, to a blank canvas. Then draw the transparent image on top.
In case you aren't drawing onto a blank canvas, you can call FillRect method of the bitmap canvas for the region you're planning to draw the png.

How can I make a form transparent according to a PNG image?

I have a PNG image that uses transparency (it is actually a circle with gradient effect from black in the middle, to transparent on the margins). I am putting this on a form using TImage. I set TForm1.Color and the TForm1.TransparentColorValue to the same value and TForm1.TransparentColor:=true.
Now, when I run the program the gradient part of the image is displayed with the color of the form. What I am looking for is to enable the transparency of the PNG image using the transparent form effect.
What am I doing wrong?
I am using Delphi 2010 Trial.
I suspect you're trying to create something like a transparent splashscreen, if that's the case, you can read these great articles, they describes a nice way to use a transparent png in a delphi form.
Alpha Blended Splash Screen in Delphi - Part 1
Alpha Blended Splash Screen in Delphi - Part 2
Bye.
Your settings are wrong. I am doing this (With a bitmap).
The TImage.Transparent should be false.
The Form.TransparentColourValue should be the colour of the part of The TImage that you want to be transparent.
The Form.TransparentColor should be True.
[Edit]
It does not matter what colour the form is if the Image covers it completely

Resources