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

How to make 2 images into 1 and have it transparant?

Started by pka4916, 8 June 2010, 04:01:17

Previous topic - Next topic

pka4916

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);

Galfar

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.


Quick Reply

With Quick-Reply you can write a post when viewing a topic without loading a new page. You can still use bulletin board code and smileys as you would in a normal post.

Name:
Email:

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

SMF spam blocked by CleanTalk