2017-05-30 3 views
0

これは私が私のUWPのアプリでこれを変換する必要があるのWinFormコードuwpアプリケーションのGraphicsクラスとPenクラスの置き換えは何ですか?

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; 
    } 

です。しかし、私はペンの代わりにBitmapとSolidColorBrushの代わりにWriteableBitmapを使うことができます。しかしGraphicsクラスのためにはどうすべきでしょうか。私はライン 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));

署名された私のイメージオブジェクトの下にこれらから離れてWriteableBitmapとしてグラフィックスを考慮すれば

とにかくすべてが解決されます。

ありがとうございます。

+0

グラフィックスは[WriteableBitmap](https://docs.microsoft.com/en-us/uwp/api/windows.ui.xaml.media.imaging.writeablebitmap)です。 – lindexi

答えて

1

クラスのSystem.Drawingの名前空間はクラスのものよりもWin2Dです。 Win2Dは、UWPアプリケーションで使用できるGPUアクセラレーションを使用した即時モードの2Dグラフィックスレンダリング用の使いやすいWindowsランタイムAPIです。

たとえば、graphics.InterpolationModeプロパティの場合は、代わりにCanvasImageInterpolationを試してみてください。 AntialiasingプロパティーはCanvasDrawingSessionと定義されており、同様のフィーチャーがSmoothingModeと定義されています。 CanvasDrawingSessionGraphicsから上記のようにFillRectangleDrawlineの方法があります。

UWPアプリでWin2Dライブラリを使用して、同じ機能を実装しようとすることができます。 Win2Dの使用方法の詳細については、official siteREADME.mdを参照し、サンプルについてはofficial samplesを参照してください。

関連する問題