【问题标题】:Drawing Pixels as Custom Shapes将像素绘制为自定义形状
【发布时间】:2013-07-18 20:44:37
【问题描述】:

我有一个源图像,我想使用http://notes.ericwillis.com/2009/11/pixelate-an-image-with-csharp/ 的方法将其缩小为像素,并将每个像素绘制为实心圆、空心圆或正方形(每个实际像素在屏幕上应约为 15px)。

我能想到的唯一方法是将每个像素创建为 usercontrolDependancyProperties 用于颜色和形状(可能绑定到路径?)。从ItemsControl 派生的父 UC 将在其内部创建数百个这样的像素 UC。

不过,这似乎是一场性能噩梦。

编辑:为了提供一些上下文,这是一个像素艺术生成应用程序。我需要将每个“像素”存储在具有 X、Y 和颜色属性的数据库中。

这是实现这一目标的最佳方式吗?

【问题讨论】:

  • 你为什么不使用位图示例来创建一个新图像并按照你想要的方式绘制每个像素。如果大小增加不变,应该很简单
  • 为什么不直接转换原图呢?
  • 您能详细说明一下这些方法吗?理想情况下,我想为每个“像素”添加一个带有十六进制代码的工具提示,因此仅使用 GDI+ 是行不通的。我不完全确定如何创建子像素。

标签: c# .net image-processing drawing pixel


【解决方案1】:

性能实际上非常令人印象深刻。我使用了UserControl(root),DependancyProperty 用于 Sprite,ItemsControl 用于多重绑定。 MultiValueConverter 将艺术点转换为 Path 元素,同时考虑到画布的大小:

<ItemsControl>
    <ItemsControl.ItemsSource>
        <MultiBinding Converter="{StaticResource dotToPixelConverter}">
            <Binding Path="Sprite.Beads" ElementName="root"/>
            <Binding Path="Sprite.Width" ElementName="root"/>
            <Binding Path="Sprite.Height" ElementName="root"/>
            <Binding Path="ActualWidth" ElementName="root"/>
            <Binding Path="ActualHeight" ElementName="root"/>
        </MultiBinding>
    </ItemsControl.ItemsSource>
    <ItemsControl.ItemsPanel>
        <ItemsPanelTemplate>
            <Canvas />
        </ItemsPanelTemplate>
    </ItemsControl.ItemsPanel>
</ItemsControl>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-12-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多