SetMenuItemBitmaps BMP transparent colour - winapi

How do I set the transparent colour of a BMP image for SetMenuItemBitmaps, I'm currently using LoadImage with uType as IMAGE_BITMAP and fuLoad as LR_LOADFROMFILE + LR_LOADTRANSPARENT?

LoadImage documents the LR_LOADTRANSPARENT flag as:
Retrieves the color value of the first pixel in the image and replaces the corresponding entry in the color table with the default window color (COLOR_WINDOW). All pixels in the image that use that entry become the default window color.
Choose a color for the first pixel that isn't used anywhere else, and paint all portions of the bitmap that are supposed to be transparent using that color.
Keep in mind that this flag is not meaningful for bitmaps with a color depth above 8bpp.

Related

Overlay text image on scene image in PIL

I have a text image and I want to overlay it over a scene image, both having the same size and in RGB mode. I have tried the ImageChops OR operation but it seems to only work on binary (mode '1'). ImageChops.add_modulo and blend functions also did not help at all. What I need is to replace the pixel values in the scene image with those from the text image. The text image has 0 (black background) and the text has the value of 255. So, the overlay should be crystal clear, although scene images are in color.
I would appreciate any help on this issue.
I managed to do it as follows:
scene_image.paste(text_img, box=None, mask=text_img.convert('1'))

Delphi XE7 - Make PNG image transparent inside Form

I set the Form Color to : clFichsia and TransparentColor: True and TransparentColorValue to : clFuchsia.
I need to remove the clFuchsia color from the Form.
Normally the image is transparent but when i load it in the application
the color of the Form doesn't disappear.
How my application looks like:
There are two different ways to handle transparency:
1) the old simplified (Windows/Delphi) way, where a specific RGB color is made transparent. This method does not allow any partial transparency (opacity is either 0% or 100%).
2) the "new" way, where you use an image with an alpha-channel, e.g. a PNG image. Each pixel has an opacity value in addition to the RGB value, which allows partial transparency (e.g. for anti-aliasing).
You are mixing those two methods. You load a PNG image with an alpha channel (method 2), but then you also set a transparent color (method 1). And the reason it looks that bad, is because the "fuchsia" RGB value in your image is not exactly the same everywhere.

How to add an image with transparency to a TDbgrid column in delphi?

I am trying to add an image to a column on a TDbgrid that takes transparency into account. When drawing the image from a TImageList on the canvas in the DBGridDrawColumnCell procedure, I need the background of the image (the same color as the pixel in the lower left corner) to take on transparency. I want this transparency area to show the highlight color or non-highlight color, especially when themes are used, such as Aero. I have been able to accomplish this in older versions of Windows with color values of clHighlight or clWindow as the background color. But with Aero themes, it always paints a box behind the non-transparent part of the image instead of the gradient blue highlight color that Aero uses. How can I accomplish this?
I believe I am supposed to use alpha channel but I'm not sure how to do this from a TImageList to a canvas. I believe the cell is painted completely with the actual highlight color before I start drawing on the canvas in the cell. I just want to draw the non-transparency part of the image and leave the background.
I was able to finally determine how to display images on a dbgrid with transparency even if themes, such as Aero is used.
I used a regular TImageList and loaded the images that I needed to display on the dbgrid. In my case there were two and they were in icon (ico) format. Instead of transferring the image to a bitmap and then drawing it to the dbgrid canvas as most old code recommends, I simply used the following simple code in the DBGridDrawColumnCell procedure:
if DataCol=0 then
begin
if (MApptsConflict.Value='<none>') then
ImageIndex := 0
else
ImageIndex := 1;
ImageList.Draw(TDBGrid(Sender).Canvas,Rect.Left+2,Rect.Top+2,ImageIndex,True);
end;
This will draw directly to the dbgrid canvas from the TImageList which will give the desired transparency.
UPDATE: I tried it with bmp's loaded in the Timagelist and it worked too.

How do I set my palette to grayscale in c++

I'm reading live feed from a mono camera and need to take a snapshot when pressing a button.
So when I convert the pointer the camera passes me to a bitmap (8 bpp) for further image processing,
the colors get all weird like this
I'm guessing it's because I didn't set the palette of the bitmap correctly, so I googled some and
came across some code in VB, which sets the color palette of a bitmap to gray scale.
I want to do the same in C++ under Visual Studio 2010, only in C++ the constructor of color palette is sealed,thus I have no way of declaring a new grayscale palette and then assign it to my bitmap.
Below is the example code I found written in Visual Basics :
Dim bmpobj As Bitmap
Dim pal As System.Drawing.Imaging.ColorPalette
pal = bmpobj.Palette
For i = 0 To 255
pal.Entries(i) = Color.FromArgb(i, i, i)
Next
bmpobj.Palette = pal
So what I'm asking is this : Is there anyway to set my bitmap's palette to grayscale ?
I think, just by changing the color palette, your image won't change to gray scale.
You will need to change each color pixel in the image to gray scale. The algorithms are here.

Writing text with alphablending on a Bitmap

I want to create a text watermark on a photo.
So, I need to render text from label without any background colors on a Bitmap and than blend this bitmap by alpha blending.
I'm trying to use Canvas.textOut method, but the result is not what I expected. Text on the bitmap always has a white background.
How can I create a bitmap with the alpha channel, which has only text?

Resources