• Welcome to Vampyre Imaging Library Forum. Please login or sign up.
 

Post reply

Other options

Shortcuts: ALT+S save/post or ALT+P preview

Topic summary

Posted by Galfar
 - 16 June 2010, 14:42:54
You need to use the canvas class which supports alpha blending.
This is my watermarking code, you can use it as inspiration:

Code (pascal) Select

  var
    Stream: TStream;
    CanvasPage: TImagingCanvas;
    Watermark: TSingleImage;
    CanvasWater: TImagingCanvas;
    R: TRect;
  begin
    Stream := TResourceStream.Create(HInstance, 'ImageWatermark', RT_RCDATA);
    Watermark := TSingleImage.CreateFromStream(Stream);
    Stream.Free;
    CanvasWater := TImagingCanvas.CreateForImage(Watermark);

    // Page.Image is a TSingleImage instance
    CanvasPage := TImagingCanvas.CreateForImage(Page.Image);
    if Page.Width > Page.Height then
      R := Rect(Round(Page.Width * 0.6), 0, Page.Width, Page.Height)
    else
      R := Rect(Round(Page.Width * 0.45), 0, Page.Width, Page.Height);
    R := ScaleRectToRect(Watermark.BoundsRect, R);
    R := Rect(R.Left, Page.Height - (R.Bottom - R.Top), R.Right, Page.Height);

    CanvasWater.StretchDrawAlpha(Watermark.BoundsRect, CanvasPage, R);   
 
    ... save to file, free canvases etc.

Posted by pka4916
 -  8 June 2010, 04:01:17
I am trying to get 2 images into 1

1 = normal pic
2 = a watermark.

so that the watermark is transparant on the picture
but all it does, is make it blank. 
How can I do it?



var
img  : timagedata;
img1 : timagedata;
img2 : timagedata;
img3 : timagedata;
begin
InitImage(Img);
InitImage(Img1);
InitImage(Img2);
loadimagefromfile(im1,img1);
loadimagefromfile(im2,img2);
newimage(214,384,ifDefault,img);
imaging.CopyRect(img1,0,0,img1.width,img1.Height,img,0,0);
imaging.CopyRect(img2,0,0,img2.width,img2.Height,img,0,192);
saveimagetofile(finalimage,img);
SMF spam blocked by CleanTalk