Add image watermark to image

ImageWatermarkInImage_test.zip (113.6 KB)

Hi

We are getting an error while water marking the image to image.
It will be a great help to us.

Please find attached solution to reproduce the error.
Specified argument was out of the range of valid values. (Parameter ‘backgroundOrigin’

Thanks
Chandra

Hi, @aroc
We appreciate your interest in Aspose.Imaging.
The cause of the issue is that a method RasterImage.Blend does not allow a negative X or Y for origin.
You can work around this by changing the following code

image.Blend(positionPoint, watermark, overlayOpacity);

with this one

// Avoid the negative coordinates in positionPoint
bool needAdjust = false;
Rectangle overlayRect = new Rectangle();
if (basePosition.X < 0)
{
    overlayRect.X = -basePosition.X;
    basePosition.X = 0;
    needAdjust = true;
}

if (basePosition.Y < 0)
{
    overlayRect.Y = -basePosition.Y;
    basePosition.Y = 0;
    needAdjust = true;
}

Point positionPoint = new(basePosition.X, basePosition.Y);
if (needAdjust)
{
    overlayRect.Width = watermark.Width - overlayRect.X;
    overlayRect.Height = watermark.Height - overlayRect.Y;
    image.Blend(positionPoint, watermark, overlayRect, overlayOpacity);
}
else
{
    image.Blend(positionPoint, watermark, overlayOpacity);
}

@aroc
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): IMAGINGNET-7673

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.