【发布时间】:2021-06-01 11:54:08
【问题描述】:
我设法创建了一个画布,用户可以使用 this Microsoft example 在其上绘图。
现在我想计算白色和黑色像素的数量。并且还修改了一些像素的颜色。
我找不到任何关于如何从画布中获取所有像素数据并对其进行操作和更新的示例。
<Page
x:Class="SDKTemplate.Scenario1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
SizeChanged="OnSizeChanged"
mc:Ignorable="d">
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid x:Name="RootGrid" Margin="12,10,12,12">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<StackPanel Margin="0,0,0,10">
<TextBlock Text="Description:" Style="{StaticResource SampleHeaderTextStyle}"/>
<TextBlock Style="{StaticResource ScenarioDescriptionTextStyle}" TextWrapping="Wrap">
This scenario adds an InkCanvas and InkToolbar to the page.<LineBreak/>
- Use either pen or mouse to ink.<LineBreak/>
- A chevron glyph on the active tool button indicates that additional settings are available in a flyout. Select the active tool once more to display the flyout.
</TextBlock>
</StackPanel>
<ScrollViewer Grid.Row="1" VerticalScrollMode="Auto" VerticalScrollBarVisibility="Auto">
<Grid HorizontalAlignment="Left" VerticalAlignment="Top">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<InkToolbar Grid.Row="0" TargetInkCanvas="{x:Bind inkCanvas}"/>
<ScrollViewer Grid.Row="1" x:Name="scrollViewer" ZoomMode="Enabled" MinZoomFactor="1" VerticalScrollMode="Enabled" VerticalScrollBarVisibility="Auto" HorizontalScrollMode="Enabled" HorizontalScrollBarVisibility="Auto">
<Grid x:Name="outputGrid" Background="{ThemeResource SystemControlBackgroundChromeWhiteBrush}" Height="Auto">
<!-- Inking area -->
<InkCanvas x:Name="inkCanvas" Height="Auto"/>
</Grid>
</ScrollViewer>
</Grid>
</ScrollViewer>
</Grid>
</Grid>
</Page>
#include "pch.h"
#include "Scenario1.xaml.h"
#include "SampleConfiguration.h"
using namespace SDKTemplate;
using namespace Platform;
using namespace Windows::Foundation;
using namespace Windows::Foundation::Collections;
using namespace Windows::UI::Core;
using namespace Windows::UI::Xaml;
using namespace Windows::UI::Xaml::Controls;
Scenario1::Scenario1()
{
InitializeComponent();
// Initialize the InkCanvas
inkCanvas->InkPresenter->InputDeviceTypes =
CoreInputDeviceTypes::Mouse |
CoreInputDeviceTypes::Pen;
}
void Scenario1::OnSizeChanged(Object^ sender, SizeChangedEventArgs^ e)
{
HelperFunctions::UpdateCanvasSize(RootGrid, outputGrid, inkCanvas);
}
我怎样才能做到这一点?
【问题讨论】:
-
您可以获取GIF图像以获取链接示例的Scenario3中的像素数据。或者,您可以使用InkStrokeContainer 类来管理
InkStroke对象的集合,参考链接示例的Scenario4。 -
如果我使用 gif 来获取像素数据并对其进行操作。我应该如何再次更新画布?因为我正在尝试实现洪水填充算法。
-
在示例的 Scenario3 中,
inkCanvas从选定的 gif 文件中获取流。 gif 文件从inkCanvas保存。我尝试对gif文件进行一些更改,并使用InkStrokeContainer.LoadAsync(IInputStream)方法将文件读入inkCanvas,但失败了。 -
因此,我认为您可以尝试将更改后的 gif 文件显示到 Image 控件中。注意将 Image 控件和 InkCanvas 放入同一个容器中,然后先添加 Image 控件。如果这种方式可以满足您的要求并且您需要,我可以向您展示代码作为示例。
-
能否请您显示一个代码示例,这对我来说更有意义。谢谢