我在C#中有BitmapImage.我需要对图像进行操作.例如灰度,在图像上添加文本等.
我在stackoverflow中找到了grayscaling函数,它接受Bitmap并返回Bitmap.
所以我需要将BitmapImage转换为Bitmap,进行操作并转换回来.
我怎样才能做到这一点?这是最好的方式吗?
我有两个.png文件添加到我的资源,我需要在进行绑定时访问他们的Uri.
我的xaml代码如下:
<Grid>
<Image>
<Image.Source>
<BitmapImage DecodePixelWidth="10" UriSource="{Binding Path=ImagePath}"/>
</Image.Source>
</Image>
</Grid>
Run Code Online (Sandbox Code Playgroud)
binding使用ImagePath的代码是:
ImagePath = resultInBinary.StartsWith("1") ? Properties.Resources.LedGreen : Properties.Resources.ledRed;
Run Code Online (Sandbox Code Playgroud)
然而
Properties.Resources.LedGreen
Run Code Online (Sandbox Code Playgroud)
返回一个Bitmap而不是String包含该特定图像的Uri.我只是想知道如何提取该值而无需在存储的目录中寻址图像的路径.(老实说,我不确定这是正确的事情,因为我在网上找不到任何类似的情况).
如果有可用的话我甚至可以选择使用的方法,请告诉我.