Opacity property #569
Closed
bhaloditarun
started this conversation in
General
Replies: 3 comments 2 replies
-
The easiest way is to convert your image by adding a transparency layer. It can be achieved with SkiaSharp, like so: QuestPDF.Infrastructure.Image LoadImageWithTransparency(string fileName, float transparency)
{
using var originalImage = SKImage.FromEncodedData(fileName);
using var surface = SKSurface.Create(originalImage.Width, originalImage.Height, SKColorType.Rgba8888, SKAlphaType.Premul);
using var canvas = surface.Canvas;
using var transparencyPaint = new SKPaint
{
ColorFilter = SKColorFilter.CreateBlendMode(SKColors.White.WithAlpha((byte)(transparency * 255)), SKBlendMode.DstIn)
};
canvas.DrawImage(originalImage, new SKPoint(0, 0), transparencyPaint);
var encodedImage = surface.Snapshot().Encode(SKEncodedImageFormat.Png, 100).ToArray();
return Image.FromBinaryData(encodedImage);
} And then used in the foreground page layer, as a watermark: Document.Create(document =>
{
document.Page(page =>
{
page.Content()
.AlignCenter()
.Text("Test")
.FontSize(192)
.FontColor(Colors.Blue.Medium)
.Bold();
var image = LoadImageWithTransparency("photo.jpg", 0.75f);
page.Foreground().Image(image);
});
}) |
Beta Was this translation helpful? Give feedback.
1 reply
-
@MarcinZiabek It's working perfectly. Very glad for your help and quick reply. Thank you again :) |
Beta Was this translation helpful? Give feedback.
0 replies
-
Is there another way to do this now? |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm using image as watermark in all pages.
Do we have any opacity property for image watermark? because text is not readable if image display in background.
Thank you in Advance!
Beta Was this translation helpful? Give feedback.
All reactions