Снимок экрана управления с различным DPI - PullRequest
0 голосов
/ 12 февраля 2019

Я могу сделать снимок экрана управления для нормального 100% DPI.Но когда значение DPI изменилось до 125%, снимок экрана выглядит некорректно.Пожалуйста, предложите подход, чтобы скриншот можно было сделать с любым DPI.Ниже приведен код

// Get absolute location on screen of upper left corner of button
System.Windows.Point locationFromScreen = this.sv.PointToScreen(new System.Windows.Point(0, 0));

// Transform screen point to WPF device independent point
PresentationSource source = PresentationSource.FromVisual(this);

System.Windows.Point targetPoints = source.CompositionTarget.TransformFromDevice.Transform(locationFromScreen);

var bmpScreenshot = new Bitmap((int)sv.ActualWidth,
                               (int)sv.ActualHeight,
                               System.Drawing.Imaging.PixelFormat.Format32bppArgb);

// Create a graphics object from the bitmap.
var gfxScreenshot = Graphics.FromImage(bmpScreenshot);

           gfxScreenshot.CopyFromScreen((int)targetPoints.X,
                                       (int)targetPoints.Y,
                                       0,
                                       0,
                                      new System.Drawing.Size((int)sv.ActualWidth, (int)sv.ActualHeight),
                                       CopyPixelOperation.SourceCopy);


byte[] data;
using (var stream = new System.IO.MemoryStream())
{
  bmpScreenshot.Save(stream, System.Drawing.Imaging.ImageFormat.Bmp);
  data = stream.ToArray();
}
            var result = Convert.ToBase64String(data);
            winObj = new Window1();

            MemoryStream ms = new MemoryStream();
            ((System.Drawing.Bitmap)bmpScreenshot).Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
            BitmapImage image = new BitmapImage();
            image.BeginInit();
            ms.Seek(0, SeekOrigin.Begin);
            image.StreamSource = ms;
            image.EndInit();

            winObj.imageViewer.Source = image;
            winObj.ShowDialog();
            bmpScreenshot.Dispose();
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...