Writing text with alphablending on a Bitmap - image

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?

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'))

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.

SetMenuItemBitmaps BMP transparent colour

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.

Resizing a png image without losing tranparency

I am trying to save a png file in database using C#.
Bitmap thumbnail = new Bitmap(file.InputStream);
thumbnail = ImageUtilities.ResizeImage(thumbnail, Convert.ToInt32(width),Convert.ToInt32(height)); ImageUtilities.SaveJpeg(path,thumbnail,Convert.ToInt32(Resources.AppConstants.ExtractThumbnailQuality);
The image gets saved in database, but with a black background around the image. In short, it loses its transparency.
If I skip the resizing of image, instead of black background, a white background appears around the image.
Can anyone suggest, how to preserve the tranparency of the image
You are saving the resized image as JPEG. JPEG does not support transparency. Save it as PNG instead

Write in a transparent colour in expression blend (WP7)

I am trying to build a windows phone live tile. I want some text on the tile that is the accent colour. What this means is that I need to draw some text on the tile that is transparent. I don't seem to be able to write in the transparent colour.
I have a User Control which is 173 by 173 pixels which I save as a png file. I use this png as the image for the live tile. The transparent bits of the image come out in the current accent colour.
Any ideas how to write in the transparent colour in xaml?
This behaviour is to be expected. In your original question you are effectively saying "Write invisible text on top of the image", and that's what you're getting (imagine writing in invisible ink on a photograph). You effectively need to do one of two things.
1) Figure out which pixels are part of the text you're writing, and "remove" them from the image so the background colour shows through, or
2) Write text in the background colour ({StaticResource PhoneAccentBrush})
EDIT
You can probably achieve what you need using an Opacity Mask. Apologies for only providing that as a link as I haven't done this myself.

Resources