Delphi TBitBtn white layer - delphi

How can I get rid of the white layer drawn under the bitmap images by Delphi/Windows when Glyph property of TBitBtn is used. I just want to draw the image, no shadow under it, no other layers that comes automatically. I am inserting round shaped 24 bit bitmap images.

Since you have a 24-bit bitmap, there is no alpha transparency, so Delphi uses the bottom left pixel of the image to determine the transparent color. All pixels with that color are treated as transparent. The part of the image with the shadow effect is not an exact match for the designated transparent color, so those pixels are painted normally, just like the rest of the image.
The shadow appears white because there was a white background in the graphic program when your designer applied the shadow effect.
Either edit the image to remove the shadow, or use a 32-bit image with alpha transparency. You'll be hard-pressed to apply alpha transparency after the fact. Fix the source image.

Related

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.

make button glyph have a transparent background in delphi 7?

I have four TSpeedButton objects, each with a BMP file assigned as a glyph for the button image. For whatever reason, delphi has decided that two of the button images should have a transparent background and two should have a white background. I created the bitmaps myself, so they are all saved at the same color depth and are using pure white (not some shade of almost white) for the background and have background color in all four corner pixels of the image.
Why would some of the glyph images show up with a transparent background and some not? What is the criterion for making the background transparent? How can I make my button images all have transparent backgrounds instead of half of them having transparent backgrounds?
Ken's comment
Delphi's glyph handling uses the pixel in the lower-left corner to determine the transparent color. All pixels that match that color should be shown as transparent. Does the lower-left pixel color match in all of the glyphs, and does it match the areas you want to be transparent? (Without the images, it's hard to tell what the problem is, but I thought I'd post this as a potential for investigation.)
appeared to hold the correct answer (sorry, can't accept a comment as the right answer!). The image I was using had a shadow reaching to the lower left corner so it was almost white in that corner and exactly white in all the other corners.
I had a similar problem with D5 and I cludged a fix for this as I never found out why it was happening.
Define the image size one Row taller than the actual image/glyph is. This will force the image to be written starting at the top left and stop just before the last row. That will force the use of a non-transparent color and the extra row below the image is not visually noticeable.

Remove Transparency From Glyph.Data in SpeedButtons

I have an old app (Delphi 5) which I want to give it some changes.
I have set a Glyph.Data for a speedbutton, but some colors are transparent and in some places I see small white dots on my image, I do not want to set transparency for the image, How to remove it (transparency)?
Any help is really appreciated.
Thanks :)
The transparency is a color that is not drawn.
You just have to change the image or set another color as the transparent one.
From Delphi 6 Help
Transparent color
Use the Transparent color drop-down to
specify which color is used to create
a mask for drawing the image
transparently. The default transparent
color is the color of the bitmap's
left-most pixel in the bottom line.
You can also change the transparent
color by clicking directly on a pixel
in the selected image.
When an image has a transparent color,
any pixels in the image of that color
are not rendered in that color, but
instead appear transparent, allowing
whatever is behind the image to show
through.
If the image is an icon, Transparent
color appears grayed and the
transparent color is set to clNone.
This is because icons are already
masked.
Set TSpeedButton.Transparent to False.
I have found the answer, Delphi thinks the transparent color is the color of most left - bottom pixel of this image. So If I set a color which is not used in my image in the most left-bottom of my image, then Delphi only will make that small pixel transparent and other parts of my image will be OK without transparency, So this post is completed by myself :))

how to add transparent pixels above and below a 32 bit bitmap images

I need to add at runtime to an inmemory image 15 lines of transparent pixels on top and 20 on the bottom.
The images are loaded in a TcxImagelist (from DevExpress Express Library), they can be therefore retrieved as 32bit bitmaps.
If the image is 400x75 after the manipulation should be 400x(75+15+20) = 400x110
How to perform this task?
There is no such a thing as "transparent" pixels. All you can do is tag them for the renderer so that it will know they aren't supposed to be displayed. here are the 3 most common ways of tagging but which one you use depends on when you're doing for rendering:
Use a transparency map: a second pixmap which indicates the "level" of transparency of each pixel. The rendered then uses that as a weighting value to combine the top and bottom layers in the final color. If you just want binary transparency (opaque/transparent), you can use a bitmap and use a simple XOR on each pixel which makes it very fast.
Define a "transparent color". You can then XOR it with the transparent color and the bottom layer. Also very fast and doesn't require any additional storage. It does have some side effects, though (one color cannot be used in the top layer image, for instance)
use the last byte of the 32-bits bitmap as the transparency level (alpha channel). In effect, you store the transparency map (255 distinct levels of transparency) with the image.
Now, in your case, since you seem to be only copying a rectangle over a rectangle, another aproach that would be: create a canvas of the same size as the final image, copy the inferior rectangle on it and the draw the to layer on top of it.

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