## 2008. július 18., péntek

Problem/Question/Abstract:

Well I have two pictures and I want to put the second on the first but with transparence. This could be usefull in many situations.

The function combines two images in a crossfade image and returns it.

function returncross(srcbit, markbit: TBitmap; srcleft, srctop, markleft, marktop:
integer): TBitmap;
var
x, y: integer;
psrc, pmark: PByteArray;
begin
srcbit.PixelFormat := pf24bit;
markbit.PixelFormat := pf24bit;

for y := 0 to markbit.Height - 1 do
begin
if y + srctop psrc := srcbit.ScanLine[y + srctop];

pmark := markbit.ScanLine[y + marktop];

for x := 0 to srcbit.Width - 1 do
begin
if (y + srctop < srcbit.Height) and (x + srcleft < srcbit.Width) then
begin
psrc^[(x + srcleft) * 3] := (psrc^[(x + srcleft) * 3] + pmark^[(x + markleft)
* 3]) div 2;
psrc^[(x + srcleft) * 3 + 1] := (psrc^[(x + srcleft) * 3 + 1] + pmark^[(x +
markleft) * 3 + 1]) div 2;
psrc^[(x + srcleft) * 3 + 2] := (psrc^[(x + srcleft) * 3 + 2] + pmark^[(x +
markleft) * 3 + 2]) div 2;
end;
end;
end;

result := srcbit;
end;

srcbit - the first picture, on the foreground
markbit - the second picture, this picture is drawed transparently
srcleft - the left coordinate of the drawed markbit
srctop  - the top coordinate ...
markleft and marktop are used if you want to take only a part of the picture (by default you can use 0)

Usage example:

Put on a form two tpicture objects (image1, image2). Load some bitmaps in them. In a button click event you can place the next line.

image1.Picture.Bitmap := putwatermark(image1.Picture.Bitmap, image2.Picture.Bitmap, 0,
0, 0, 0);