PaintView.MAUI 1.1.0

dotnet add package PaintView.MAUI --version 1.1.0                
NuGet\Install-Package PaintView.MAUI -Version 1.1.0                
此命令旨在在 Visual Studio 的包管理器控制台中使用,因为它使用 NuGet 模块的 Install-Package 版本。
<PackageReference Include="PaintView.MAUI" Version="1.1.0" />                
对于支持 PackageReference 的项目,请将此 XML 节点复制到项目文件中,以引用软件包。
paket add PaintView.MAUI --version 1.1.0                
#r "nuget: PaintView.MAUI, 1.1.0"                
#r 指令可以在 F# Interactive 和 Polyglot Notebooks 中使用。请将其复制到交互式工具或脚本的源代码中,以引用软件包。
// Install PaintView.MAUI as a Cake Addin
#addin nuget:?package=PaintView.MAUI&version=1.1.0

// Install PaintView.MAUI as a Cake Tool
#tool nuget:?package=PaintView.MAUI&version=1.1.0                

PaintView.MAUI

使用触摸控制的绘图视图控制

PaintView

使用查找器、鼠标或指针绘图的跨平台控件。视图拥有属性,可以作为清晰的绘图区域使用,也可以使用其控制按钮

View with control buttons

View without control buttons

属性

/// Binding property for use this control in MVVM.
public PaintView Self
/// Drawing area backgroud color
public new Color BackgroundColor
/// Show/Hide color selector button.
public bool ShowColorSelector
/// Show/Hide pointer size selector button.
public bool ShowPointerSelector
/// Show/Hide undo and redo buttons.
public bool ShowUndoRedoButtons
/// Show/Hide figures draw toolbar.
public bool ShowFigureButtons
/// Sets the size for control buttons.
public float ButtonsSize
/// Sets the border color for control buttons.
public Color ButtonsBorderColor
/// Sets the background color for control buttons.
public Color ButtonsBackgroundColor
/// Sets the background color for control buttons selected in toolbar.
public Color SelectedButtonBackgroundColor
/// Sets the drawing color.
public Color SelectedColor
/// Sets the drawing pointer size.
public float SelectedPointer
/// If true, control buttons are hidden while user draws.
public bool HideButtonsOnDrawing
/// Minimun movement distante for start to draw.
public float MinDistanceBetweenDrawingPoints
/// Colors list to show in the palette.
public List<Color> Palette
/// Pointers sizes list to show in the pointer selector.
public List<float> Pointers
/// Sets the rectangle area where user can draw.
public Rect DrawBounds

方法

/// Initialize the Paint view.
public void Reset(bool clearNoUnDoDraws = true)
/// Gets a bytes[] representation from drawing area snapshot.
public async Task<byte[]> GetSnapshotBytesAsync(bool onlyDrawBounds = true, SKEncodedImageFormat format = SKEncodedImageFormat.Png, int quality = 100)
/// Gets an image representation from drawing area snapshot.
public async Task<ImageSource> GetSnapshotAsync(bool onlyDrawBounds = true, SKEncodedImageFormat format = SKEncodedImageFormat.Png, int quality = 100)
/// Undo the drawing steps indicated.
public void UnDo(int steps = 1);
/// Redo the drawing steps indicated.
public void ReDo(int steps = 1)
/// Draws a line in the indicates coordinates.
public void DrawLine(Point start, Point end, Color color, float pointerSize, bool canBeUnDo = true)
/// Draws an oval in the indicates coordinates.
public void DrawOval(Point start, Point end, Color strokeColor, Color fillColor, float pointerSize, bool canBeUnDo = true)
/// Draws a rectangle in the indicates coordinates.
public void DrawRect(Point start, Point end, Color strokeColor, Color fillColor, float pointerSize, bool canBeUnDo = true)
/// Draws a text in the indicates coordinates.
public void DrawText(Point start, string text, Color strokeColor, Color fillColor, float pointerSize, float fontSize, float scaleX = 1, bool canBeUnDo = true)

安装和配置 PaintView

  1. 在您的应用程序中下载并安装 PaintView.MAUI NuGet 软件包。

  2. MauiProgram.cs 中初始化插件

    // Add the using to the top
    using PaintView.MAUI;
    
    public static MauiApp CreateMauiApp()
    {
    	var builder = MauiApp.CreateBuilder();
    
    	builder
    		.UseMauiApp<App>()
    		.UsePaintView(); // Add the use of the plugging
    
    	return builder.Build();
    }
    

使用 PaintView

在 XAML 中,请确保添加正确的 XML 命名空间

xmlns:pv="clr-namespace:PaintView.MAUI;assembly=PaintView.MAUI"

使用控件

    <Grid>
        <pv:PaintView Grid.Row="0" HorizontalOptions="Fill" VerticalOptions="Fill" BackgroundColor="White"
                      ShowColorSelector="True" ShowPointerSelector="True" ShowUndoRedoButtons="True"
                      ButtonsSize="40"
                      BindingContext="{x:Reference mpage}" Self="{Binding PaintView}"/>
    </Grid>

使用事件

    private void Button_Clicked(object sender, EventArgs e)
    {
        PaintView.Reset();
    }

    private async void Button_Clicked_1(object sender, EventArgs e)
    {
        image.Source = await PaintView.GetSnapshotAsync();
    }

    private void Button_Clicked_2(object sender, EventArgs e)
    {
        PaintView.UnDo();
    }

    private void Button_Clicked_3(object sender, EventArgs e)
    {
        PaintView.ReDo();
    }
    private void Button_Clicked_4(object sender, EventArgs e)
    {
        PaintView.DrawRect(new(200, 100), new(300, 200), Colors.Black, Colors.Cyan, 2);
        PaintView.DrawOval(new(200, 100), new(300, 200), Colors.Black, Colors.Cyan, 2, false);
        PaintView.DrawLine(new(200, 100), new(300, 200), Colors.Black, 2);
    }
产品 兼容和额外计算的目标框架版本。
.NET net7.0 兼容。 net7.0-android 已计算。 net7.0-android33.0 兼容。 net7.0-ios 已计算。 net7.0-ios16.1 兼容。 net7.0-maccatalyst 已计算。 net7.0-maccatalyst16.1 兼容。 net7.0-macos 已计算。 net7.0-tvos 已计算。 net7.0-windows 已计算。 net7.0-windows10.0.19041 兼容。 net8.0 已计算。 net8.0-android 已计算。 net8.0-browser 已计算。 net8.0-ios 已计算。 net8.0-maccatalyst 已计算。 net8.0-macos 已计算。 net8.0-tvos 已计算。 net8.0-windows 已计算。
兼容的目标框架
包含的目标框架(在包中)
了解有关目标框架.NET Standard的更多信息。

NuGet 包

此包未被任何 NuGet 包使用。

GitHub 仓库

此包未被任何流行的 GitHub 仓库使用。

版本 下载 最后更新
1.1.0 202 5/2/2023
1.0.0 138 4/27/2023

添加了 DrawBounds 和 DrawText