CImage:Imbed


The Imbed method pastes an image into the current image. The second image is imbedded at coordinate offsets that are integral values. If fractional pixel positioning is needed, first use Shift for the fractional pixel offsets followed by Imbed for the full pixel offsets. This method has two forms: one for an opaque imbedding, and the other for a transparent imbedding that combines the values from both images.

Syntax

bSuccess = CImage:Imbed( CImage2, dx, dy )

bSuccess = CImage:Imbed( CImage2, dx, dy, nTransparency )

where

    CImage2 is the other image to be imbedded in the current one.

    dx and dy are the (column, row) offsets of the origin of CImage2.

    nTransparency is a percent transparency of the current image, between 0 and 100.

    bSuccess is the returned success code. On success it is true, otherwise false.

  

This method imbeds a second image (the CImage2 parameter) into the current CImage object. The current CImage object is therefore a a background, or "canvas", into which the second image is pasted. The imbedding can be either opaque or transparent. If no transparency value is specified, an opaque insertion is done—that is, the second image replaces the current image underneath it.

The nTransparency parameter specifies the percent transparent of the current (background) image. This applies only over the region where the two images overlap. To describe transparent imbedding mathematically, consider imbedding image II into the current image IBG which acts as the background. Converting nTransparency from percentage T to a decimal value t, we have the following equation for the intensity of the final image I:

           

For example, if nTransparency = 25, then the current image is only 25% transparent, and the resulting image contains 75% of the current image. By this definition, the opaque mode corresponds to a transparency of 100 percent, in which the current image is totally transparent and is replaced by the imbedding image.

The insertion point is determined by coordinate offsets applied to the origin ("corner") of the second image. Setting dx=0, dy=0 imbeds the CImage2 into the current image with the two origins aligned. Setting dx=400, dy=100 imbeds CImage2 so that its corner is shifted (400,100) pixels relative to the current image. In this case, since image coordinates are measured relative to (1,1), the corner of CImage2 will appear at coordinate (401,101) in the current image

Example

Suppose that a CImage I and a second CImage I2 exist. The following script imbeds I2 into the current image I1. The corner of I2 is offset by (100,250) in image I, and the pixel values are merged with 50% transparency:

dx = 100 ; dy = 250

-- position the origin of I2 at these offsets

I:Imbed( I2, dx, dy, 50 )

-- perform the operation on image I

Related Topics

Expand

CImage class

CRect class