2017-05-30 37 views
0

這是一個WinForm代碼什麼是UWP應用程序中的圖形和筆類的替代?

private EasyScript eScript; 
    /// <summary> 
    /// Graphics object we'll draw on to in order to produce a signature 
    /// image. 
    /// </summary> 
    private Graphics graphics; 
    /// <summary> 
    /// Raster backing the graphics object. 
    /// </summary> 
    private Bitmap raster; 
    /// <summary> 
    /// Pen we'll use to create strokes on our graphics object. 
    /// </summary> 
    private Pen pen; 
    /// <summary> 
    /// The last point we captured. 
    /// </summary> 
    private Coordinate lastPoint = null; 
    /// <summary> 
    /// Whether or not the next event we receive should clear the signature. 
    /// </summary> 
    private bool clearOnNext = false; 
    /// <summary> 
    /// The current stroke count. 
    /// </summary> 
    private int strokeCount = 0; 
    /// <summary> 
    /// The amount to scale the coordinates by. 
    /// </summary> 
    private double scaleFactor = 1; 

    /// <summary> 
    /// Initializes a new instance of the <see cref="ExampleForm"/> class. 
    /// </summary> 
    public ExampleForm() 
    { 
     //Create a new EasyScript object. 
     this.eScript = new EasyScript(); 

     //Register ourselves as a signature listener. 
     eScript.AddListener(this); 

     //Initialize our form. 
     this.InitializeComponent(); 

     //Initialize our drawing components. 
     raster = new Bitmap(signaturePictureBox.Width, signaturePictureBox.Height); 
     graphics = Graphics.FromImage(raster); 

     //Enable high quality drawing. 
     graphics.InterpolationMode = InterpolationMode.HighQualityBicubic; 
     graphics.CompositingQuality = CompositingQuality.HighQuality; 
     graphics.SmoothingMode = SmoothingMode.AntiAlias; 
     pen = new Pen(Brushes.Black); 

     //Calculate our scale factor based on the size of the picture box. 
     scaleFactor = signaturePictureBox.Width/eScript.GetSignatureProtocol().GetWidth(); 

     //Clear the picture box. 
     ClearSignatureBox(); 

     // this allows the form to preview all keyboard events before other parts of the form are allowed 
     // to get them. If a particular keyboard event is from a ScripTouch device, 
     // we can prevent the event from propogating to other form elements, such as a TextBox. 
     this.KeyPreview = true; 
     this.cardSwipeInfoTextBox.ReadOnly = true; 
     this.signatureInfoTextBox.ReadOnly = true; 
    } 

我需要轉換這在我UWP應用程序。但是,我可以使用WriteableBitmap代替位圖和SolidColorBrush來代替筆。但是Graphics類應該是什麼。如果我從這些考慮顯卡的WriteableBitmap的開行以下 graphics.InterpolationMode = InterpolationMode.HighQualityBicubic; graphics.CompositingQuality = CompositingQuality.HighQuality; graphics.SmoothingMode = SmoothingMode.AntiAlias;

graphics.FillRectangle(Colors.White, 0, 0, signature.Width, signature.Height);

graphics.DrawLine(pen, (float)(lastPoint.X * scaleFactor), (float)(lastPoint.Y * scaleFactor), (float)(coordinate.X * scaleFactor), (float)(coordinate.Y * scaleFactor));

簽名我的圖像對象

總之一切都解決了。

在此先感謝。

+0

圖形是[WriteableBitmap](https://docs.microsoft.com/en-us/uwp/api/windows.ui.xaml.media.imaging.writeablebitmap) – lindexi

回答

1

System.Drawing命名空間下的Graphics類更像是CanvasDrawingSession類的Win2D。 Win2D是一個易於使用的Windows運行時API,可用於UWP應用程序,可用於即時模式的2D圖形渲染以及GPU加速。

例如,對於graphics.InterpolationMode屬性,您可以嘗試CanvasImageInterpolationCanvasDrawingSessionAntialiasing屬性定義了與SmoothingMode相似的特徵。 CanvasDrawingSession也有FillRectangleDrawline方法,如上所示從Graphics

因此,您可以嘗試在UWP應用程序中使用Win2D庫來實現相同的功能。有關如何使用Win2D的更多詳細信息,請參考official siteREADME.md,有關樣本請參閱official samples

相關問題