ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
Forum membership is Free!  Click Join to sign-up
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 PNG with transparent background + 40% opacity
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

aleatprog

132 Posts

Posted - May 18 2024 :  04:25:01  Show Profile  Reply
Hi,

in order to watermark a PDF by adding an image to the highest z-index, I got an acceptable result by using a PNG with transparent background + 40% opacity (see image below).

The following code creates an image with transparent background, but I miss the point how to apply 40% opacity to the watermark text in order to get the underlaying text readable.

ievPng := TImageEnView.Create(nil);
  try
    with ievPng do
      begin
        IEBitmap.CreateAsAlphaChannel(992, 1403, ieMemory);
        LayersAdd('copyrighted extract - ' + FormatDateTime('c', Now), 28, clWebGainsboro, 'Arial');
        TIETextLayer(CurrentLayer).Rotate := 60;
        TIETextLayer(CurrentLayer).SizeToText();
        CurrentLayer.PosX := IELayer_Pos_HCenter;
        CurrentLayer.PosY := IELayer_Pos_VCenter;
        LayersMergeAll(True);
        Proc.SetTransparentColors(CreateRGB(255, 255, 255), CreateRGB(255, 255, 255), 0);
        Update;
        ImageEnView1.PdfViewer.Objects.AddImage(0, 0, Round(ImageEnView1.PdfViewer.PageWidth * 0.6), Round(ImageEnView1.PdfViewer.PageHeight * 0.6), ievPng.IEBitmap);
      end;
  finally
    ievPng.Free;
  end;
ImageEnView1.PdfViewer.ApplyChanges;
ImageEnView1.PdfViewer.SaveToFile(path);


Ale

aleatprog

132 Posts

Posted - May 18 2024 :  04:41:14  Show Profile  Reply
Solved.

Simply apply transparency to the text color. For watermarks, as in my case, transparency could be applied to all colors of the bitmap. The result is perfect.

//set background transparent
Proc.SetTransparentColors(CreateRGB(255, 255, 255), CreateRGB(255, 255, 255), 0);
//apply 40% opacity to the bitmap
Proc.SetTransparentColors(CreateRGB(0, 0, 0), CreateRGB(254, 254, 254), 40);

Ale
Go to Top of Page

xequte

38608 Posts

Posted - May 20 2024 :  00:13:27  Show Profile  Reply
Nice one, Ale

Nigel
Xequte Software
www.imageen.com
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: