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

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.

Related

Transparent Circle inside a White Rectangle

I'm working on a report project and would like to avoid making a separate image for each indicator color. Ideally, I like to put a transparent circle in a white rectangle. I have Snag-It available and general Windows tools.
My plan is to put the Image in a table cell and change the color of the circle by dynamically assigning the background color of the cell. I think it would be much easier to embed this one image, rather than creating a bunch of different colored circles that all have to be embedded.
Any suggestions on how I can do this in Snag-It or Paint, or any tools that are free for commercial use that you can recommended for this?
This sounds like a good workaround to get an indicator with whatever color you want.
Paint.net is a free image editor that you could create this in. Start with a white square. Use the Ellipse Select tool to select a circle in the middle. Press the Delete key to make it transparent. Save it as a .PNG file and embed it in the report.

Delphi PNGImage - Image transparency is not pure

I am using PNG images as main image resource in my application. Since im using Delphi 7, i downloaded PNGImage lib and included it in project. I load images like this:
Form.image.Picture.LoadFromFile(PAnsiChar('\background.png'));
Image has transparent and semi transparent pixels on its border. The problem i get is that transparent pixels are filled with random zoomed part of my desktop with currently opened windows, while i expected to see what is actually located beneath form.
Additionally, form has this properties:
BorderStyle: bsNone;
TransparentColor: true;
Visible: false;
Here is a picture of current state (above black line) and desired:
Can this be fixed somehow or it is how delphi deals with transparency?
To have the form "shade" what's beneath it, use the forms AlphaBlend and AlphaBlendValue properties. The .png image doesn't have to be partially (alpha blended) transparent, but it can be.
If you want the form to be semi-transparent you use Alphablending, that's a limitation of Windows. In addition you can have a certain color fully transparent. In the following sample the forms color is clGray, which is also defined as the Transparent color property in addition to the Transparent property set to True. The image, aligned alClient, is 50% transparent, placed on a TImage which is set as transparent, but even so, it doesn't show up as semi-transparent unless you have AlphaBlending on. Again, this is a limitation of Windows. The best you can do is try with a fairly high value for AlphaBlendingValue (240..250) and a rather light image to find the right compromise.

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.

Edit only alpha layer in GIMP

I'm trying to create a "corona" effect (like the sun's corona) in an image using GIMP, but I'm having trouble editing only the alpha channel of the image.
I want the RGB to be pure white (255, 255, 255) and the alpha layer to have a brush effect applied to it. I know how to use the brush, but no matter what combination of masks or layer visibility / channel visibility settings I try, it will never edit ONLY the alpha channel, leaving the rest undisturbed.
How can I edit only the alpha channel of an image in GIMP?
To edit the alpha channel, add a layer mask and apply the brush effect to the layer mask.
Under the Layers tab, right click the layer to edit and choose Add Layer Mask. A dialog box will ask you how you want the layer mask to be initialized. Presuming you'll start with a visible image and brush away the part you want transparent, the best choice is White (Full Opacity). Click Add.
Under the Layers tab, you should now see the white thumbnail of the layer mask, next to the thumbmail of the layer image. Click on the thumbnail to edit the layer mask. Choose your brush effect and the color black, and apply your brush effect.
If you switch to the Channels tab, you will see in real time how the alpha channel changes as you paint on the layer mask.
If you prefer to start with a transparent image and brush on the part you want visible, just start with a layer mask which is Black (Full Transparency) and apply your brush effect to the layer mask with the color white.
You can always switch back and forth between black and white paint to add or remove transparency on the layer mask.
When you want to return to editing the layer image instead of the layer mask, go back to the Layers tab and click on the thumbnail of the layer image.
Just a simple solution only if you want to change the transparency of the layer.
Choose eraser tool. There is an option to change the opacity of the eraser under tool options. Just adjust it to your requirement(say 75). Now apply the eraser.
Just another method I found using a buggy appimage (eraser and masks not usable):
If you open the channels and deactivate the RGB channels, you can make hard selections on the image and use the fill tool, editing the opacity for gray-values.
Just double click on the layer you want to change the transparency and change the opacity

Replaceing color on a image realtime

First of all I will explain my situation so you can know my problem a little better. I'm making a HTML5 app. I have a canvas, and using a color picker you can change the color of the canvas. Now i have a picture which I want to put on the canvas but that pictures color needs to be changed using a color picker. So i need to replace, lets say, black color on that picture and put it on the canvas so it dosnt screw up the background.
So that will look like this:
1st color picker- changes the color of the canvas
2nd color picker - replaces the black color on the image with the one in the color picker and puts it on the canvas
Now my problem is how to replace the color on the image without reloading the page.
My only condition is no using silverlight, flash, java or any other similar tehnology that need 3rd party software to be installed on the device.
Thanks in advance.
If you dont understand my query fully, feel free to ask.
My approach with a JS only solution could be:
Loading the image inside a canvas element. Look at the MDC canvas tutorial
Trigger the user click on the canvas and get the pixel color (see links below to know how to get the color of a pixel) and look at this answer to get the mouse position
Substitute all the colors in the canvas with the one the user pick. For some examples about pixel manipulation:
Pushing pixel with canvas at Mozilla Hacks
http://beej.us/blog/2010/02/html5s-canvas-part-ii-pixel-manipulation/
This JS at mezzoblue apply heavy filter to an image
After some canvas experiment I notice that mostly in all the browser the pixel manipulation with canvas could be very slow also with small images. So another experiment to do could be to get the pixel color and then:
pass the color information to a PHP (or another server side script) with an AJAX call
do the color manipulation with an image library like GD or imagemagik
return back your image with the Ajax response
reload your canvas with the modified version of the image

Resources