Hello group
Recently I had to print image in CMYK color space. I didn't find support in WPF version so I wrote my own function that should be called instead of PdfSharp.Pdf.Advanced.PdfImage.ReadTrueColorMemoryBitmap (code below). Is there any way to extend the basic functionality? The PdfImage class is sealed.
BTW BitmapSource.CopyPixels requires SecurityPermissionFlag.UnmanagedCode
Code:
private void readCmykMemoryBitmap() {
Debug.Assert(this.image.wpfImage.Format == PixelFormats.Cmyk32,"Only CMYK support");
int _nOfChannels = 4;
int height = this.image.PixelHeight;
int width = this.image.PixelWidth;
byte[] _destImageData = new byte[_nOfChannels * width * height];
int _stride = _nOfChannels * width;
this.image.wpfImage.CopyPixels(_destImageData,_stride,0);
FlateDecode fd = new FlateDecode();
byte[] imageDataCompressed = fd.Encode(_destImageData);
Stream = new PdfStream(imageDataCompressed,this);
Elements[Keys.Length] = new PdfInteger(imageDataCompressed.Length);
Elements[Keys.Filter] = new PdfName("/FlateDecode");
Elements[Keys.Width] = new PdfInteger(width);
Elements[Keys.Height] = new PdfInteger(height);
Elements[Keys.BitsPerComponent] = new PdfInteger(8);
Elements[Keys.ColorSpace] = new PdfName("/DeviceCMYK");
if(image.Interpolate)
Elements[Keys.Interpolate] = PdfBoolean.True;
}