Blend 2 images with blend modes

From Director Online Wiki
Jump to: navigation, search
-- lbxBlendImages
--
-- DESCRIPTION:
-- Blend 2 images with given blendMode
--
-- PARAMETERS:
-- lowImg is the base image object
-- topImg is the image object to be blended on top of lowImg
-- blendMode is the string of the blend mode to apply.
--   The 14 possible values are:
--   "normal"
--   "layer"
--   "multiply"
--   "screen"
--   "lighten"
--   "darken"
--   "difference"
--   "add"
--   "subtract"
--   "invert"
--   "alpha"
--   "erase"
--   "overlay"
--   "hardlight"
--
-- EXAMPLE:
-- myImg = lbxBlendImages(member("img1").image, member("img2").image, "multiply")
 
on lbxBlendImages img1, img2, blendMode
  lowImg = convert(#bitmapdata, img1)
  topImg = convert(#bitmapdata, img2)
 
  tColor  = newObject("flash.geom.ColorTransform")
  tMatrix = newObject("flash.geom.Matrix")
  lowImg.draw(topImg, tMatrix, tColor, blendMode)
 
  img = convert(#image, lowImg)
  lowImg.dispose()
  topImg.dispose()
 
  return img
end

Tested on D10/D11 on Windows XP

Please note that the maximum dimensions for BitmapData-Objects are 2880px width and height.

More info about possible blend modes