views:

60

answers:

1

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?

+2  A: 

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.

Stephane
Hi, thanks, could you post some code for the implementation of the canvas idea? It seems suitable for my approach.
err... it's really trivial code, you know: TCanvas.CopyRect and you're done.
Stephane