PDFsharp & MigraDoc Foundation
http://forum.pdfsharp.com/

How to add image with partial opacity value?
http://forum.pdfsharp.com/viewtopic.php?f=2&t=3830
Page 1 of 1

Author:  AssassinLV [ Wed Aug 22, 2018 5:13 am ]
Post subject:  How to add image with partial opacity value?

Hello.
So I can't find any example on how to add a partially transparent image to PDF (like a watermark of sort). I know that quite some time ago it was possible (via a bug) to set the opacity with the XBrush value, but sadly it was a bug and even more sadly it is fixed.. There is an example called "Draw a PNG image with transparency", but it does not say on whether it's just the "white background transparent" image or it is with opacity with for example 10% opaque, and more so it uses a comment-less helper method which does much more then I require...

Thanks beforehand! :)

EDIT 1:
Also I am aware that System.Drawing allows to change color matrix for Bitmap image - to be able to draw images with opacity with floating point from 0 to 1... Which as it seems is not supported by PdfSharp.

Author:  Thomas Hoevel [ Wed Aug 22, 2018 8:06 am ]
Post subject:  Re: How to add image with partial opacity value?

Hi!

You can download the source code and search this:
Code:
// The transparency set for a brush also applies to images. Set opacity to 100% so image will be drawn without transparency.
_gfxState.RealizeNonStrokeTransparency(1, _colorMode);


It's a matter of minutes to add a property for the opacity and use that property instead of the value "1" in the second line.

Author:  AssassinLV [ Wed Aug 22, 2018 8:32 am ]
Post subject:  Re: How to add image with partial opacity value?

Why is it hard-coded in the first place?

I can't edit the source - as I am using Nugget version of the PdfSharp.. And even if I could - it would be overridden by the first nugget update..

Author:  Thomas Hoevel [ Wed Aug 22, 2018 8:45 am ]
Post subject:  Re: How to add image with partial opacity value?

AssassinLV wrote:
I can't edit the source - as I am using Nugget version of the PdfSharp.. And even if I could - it would be overridden by the first nugget update..
Anybody who can handle Notepad.exe can edit the source.
NuGet won't overwrite anything if you compile the assemblies on your own computer and use them.

I cannot say why the API is as it is.

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/