uwp应用程序中Graphics和Pen类的替换是什么? [英] What is the replacement of Graphics and Pen class in uwp app?

查看:65
本文介绍了uwp应用程序中Graphics和Pen类的替换是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是WinForm代码

This is a WinForm code

 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代替Bitmap,并使用SolidColorBrush代替Pen.但是Graphics类应该是什么.

I need to convert this in my UWP app. However i can use WriteableBitmap in place of Bitmap and SolidColorBrush in place of Pen. But what should be for Graphics class.

如果我将图形视为下面的几行,将图形视为WriteableBitmap,无论如何一切都可以解决graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;graphics.CompositingQuality = CompositingQuality.HighQuality;graphics.SmoothingMode = SmoothingMode.AntiAlias;

Anyhow everything is solved if i consider graphics as a WriteableBitmap apart from these below lines 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));

签名是我的图像对象.

提前谢谢.

推荐答案

Win2D .Win2D是易于使用的Windows运行时API,可通过GPU加速进行即时模式2D图形渲染,可用于UWP应用.

The Graphics class under System.Drawing namespace is more like CanvasDrawingSession class of Win2D. Win2D is an easy-to-use Windows Runtime API for immediate mode 2D graphics rendering with GPU acceleration which is available for UWP app.

例如,对于 graphics.InterpolationMode 属性,您可以尝试 CanvasImageInterpolation . CanvasDrawingSession 定义了与 SmoothingMode 相似的功能. CanvasDrawingSession 也具有 FillRectangle Drawline 方法,如上所示来自 Graphics .

For example, for graphics.InterpolationMode property you may try CanvasImageInterpolation instead. The Antialiasing property of CanvasDrawingSession defined similar features as SmoothingMode has. CanvasDrawingSession also has FillRectangle and Drawline methods as you showed above from Graphics.

因此,您可以尝试在UWP app中使用Win2D库来实现相同的功能.有关如何使用Win2D的更多详细信息,请参考官方站点<的 README.md /a>,有关示例,请参考官方示例.

So you can try to use Win2D library in UWP app to implement the same features. For more details about how to use Win2D please reference the README.md of the official site and for samples please reference the official samples.

这篇关于uwp应用程序中Graphics和Pen类的替换是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆