0

This is the snippet of code I will focus on

int Width = (int)InkControl.ActualWidth, Height = (int)InkControl.ActualHeight;
InkControl.Background = Brushes.White;
var Renderer = new RenderTargetBitmap(Width, Height, 96d, 96d, PixelFormats.Default);
System.Drawing.Bitmap SignImage = null;
using (MemoryStream OutStream = new MemoryStream())
{
    Renderer.Render(InkControl);
    var Encoder = new JpegBitmapEncoder();
    Encoder.QualityLevel = 100;
    Encoder.Frames.Add(BitmapFrame.Create(Renderer));
    Encoder.Save(OutStream);
    SignImage = new System.Drawing.Bitmap(OutStream);
}

Everything is fine and in SignImage I have my image saved. Anyway when I resize it (mantaining proportion but reducing the size) it becomes very pixelated and horrible. Is there is a way to avoid this and apply a proper scale to resize the image?

After this I have to put this image in a Signature Appearence in a PDF using iTextSharp, after this it loses again resolution, becoming a really really unrecognizable trait.

I'm developing in windows 7, with .NET 4.5 and Visual Studio 2013. The application has to be deployed in a Window Surface Device, with Windows 8.

This is the snippet for iText code

PdfSignatureAppearance SignAppearence = SignStamper.SignatureAppearance;
var rect = new iTextSharp.text.Rectangle(left, bottom, left + signImage.Width, bottom + signImage.Height);
SignAppearence.SetVisibleSignature(rect, page, fieldName: SignAppearence.GetNewSigName());
SignAppearence.SignatureGraphic = iTextSharp.text.Image.GetInstance(signImage, ImageFormat.Jpeg);
SignAppearence.SignatureRenderingMode = PdfSignatureAppearance.RenderingMode.GRAPHIC;
Alexis Pigeon
  • 7,423
  • 11
  • 39
  • 44
Razlo3p
  • 455
  • 2
  • 7
  • 28
  • 2
    How exactly do you resize the image? Have you tried using a different encoder, e.g. BmpBitmapEncoder? – Clemens Oct 07 '14 at 11:32
  • Increase the size of the control *before* you create the image... perhaps even put it into a `ViewBox` and use that as the `Visual` to create the image from... that should give you a larger high resolution image. – Sheridan Oct 07 '14 at 11:58
  • *After this i have to put this image in a Signature Appearence in a PDF using IText Sharp, after this it loose again resolution, becoming a really really unrecognizable trait.* - You might want to show your code for that, too, because you probably do something wrong here. – mkl Oct 07 '14 at 12:12
  • @Clemens this is how i resize the image `ActualSign = new Bitmap(Surface.StoredSignAppearence, new Size(width, height));` i've tried other Encoder but the result is the same (except for some background color change) @Sheridan i did not understand well your answer. I have to let hte image smaller than the original, not bigger. – Razlo3p Oct 07 '14 at 12:56
  • @mkl i edited the original Question to answer your point, thanks! – Razlo3p Oct 07 '14 at 12:58

0 Answers0