Search code examples
c#printingdpixps

Printing XPS document with image. Different image size when set different dpi


I printing XPS document with images, that contains QR-codes. Image creating sample here:

 Image image = CreatePresentation(qrCode);
 image.Height = 200;
 image.Width = 200;
 image.HorizontalAlignment = HorizontalAlignment.Center;
 image.VerticalAlignment = VerticalAlignment.Center;
 image.Stretch = Stretch.None;

where

 public static Image CreatePresentation(System.Drawing.Image source)
    {
        Stream stream = new MemoryStream();
        source.Save(stream, ImageFormat.Png);
        Image image = new Image();

        BitmapImage src = new BitmapImage();
        src.BeginInit();
        src.StreamSource = stream;
        src.EndInit();

        image.Source = src;
        return image;
    }

When i have monitor dpi=96 then image size on printed page (on paper after printing) more larger than when i have montor dpi=120. How i can print images with the same size on different dpi?


Solution

  • When i replaced

     image.Stretch = Stretch.None;
    

    on

     image.Stretch = Stretch.Fill;
    

    image began print correct