TImage32.CopyBlend

function CopyBlend(src: TImage32; srcRec, dstRec: TRect; blendFunc: TBlendFunction = nil): Boolean;


This function copies part or all of another image into the specified destination (dstRec).

When no blend function is provided, the contents of srcRec will simply overwrite whatever's in dstRec. However if srcRec and dstRec aren't the same size, then the srcRec image will be stretched to fit dstRec. (A blend function isn't needed when 'src' is fully opaque.)

When 'src' contains some transparency, then a blend routine is required to properly merge the two images. The library provides several predefined blend routines which will cover just about all blending requirements. Nevertheless, the library user can also use their own custom blend routines (using the TBlendFunction template). The 3 main predefined blend functions are - BlendToAlpha, BlendToOpaque & BlendMask.


Example 1

  uses Image32, Image32_PNG;
  ...
  img := TImage32.Create;
  img.LoadFromFile('green_circle_blurred.png');
  img2 := TImage32.Create;
  img2.LoadFromFile('beetle.png');
  img.CopyBlend(img2, img2.Bounds, img.Bounds, BlendToAlpha);
  img.SaveToFile('beetle_on_green.png');
  img.Free;
  img2.Free;
      
Before:
After:

Example 2

  uses Image32, Image32_PNG;
  ...
  img := TImage32.Create;
  img.LoadFromFile('lenna.png');
  img2 := TImage32.Create;
  img.LoadFromFile('green_circle_blurred.png');
  img.CopyBlend(img2, img2.Bounds, img.Bounds, BlendMask);
  img.SaveToFile('lenna_masked.png');
  img.Free;
  img2.Free;
      
Before:
After:

See Also

BlendMask, BlendToAlpha, BlendToOpaque, TBlendFunction