将位图图像绑定到数据库时设置源属性
我正在使用以下代码将数据库(compact sql)中的图像绑定到我的图像控件:
<Image MaxHeight="100" Stretch="UniformToFill">
<Image.Source>
<BitmapImage DecodePixelHeight="200"
StreamSource="{Binding ImageData}" />
</Image.Source>
</Image>
使用 BitmapImage 的原因是因为我发现当我使用图像时,呈现的缩略图太大它减慢了程序的速度。我打算在位图图像中使用 DecodePixelHeight
属性,以允许我使用较小的缩略图大小,从而防止我的程序变慢。
将其绑定到我的图像时遇到的问题是一个错误,指出我没有正确设置 StreamSource
。我有一种感觉,这是因为我的图像以字节形式存储在数据库中(事先转换),并且 BitmapImage
(与标准 Image
不同)不支持自动转换为图像格式。
这是正确的吗?如果是这样,我是否只需要实现一个转换器?
I am using the following code to bind an image from my database (compact sql) to my image control:
<Image MaxHeight="100" Stretch="UniformToFill">
<Image.Source>
<BitmapImage DecodePixelHeight="200"
StreamSource="{Binding ImageData}" />
</Image.Source>
</Image>
The reason for using BitmapImage
is because I found that when I used image, the thumbnails presented were so large that it slowed the program down. I intend on using the DecodePixelHeight
property within bitmapimage to allow me to use a smaller thumbnail size and hence keep my program from slowing down.
The issue I get when binding this to my image is an error saying I have not set StreamSource
correctly. I have a feeling this is because my image is stored as bytes in the database (converted before hand) and that BitmapImage
(unlike the standard Image
) does not support automatic converting into an image format.
Is this correct? If so, do I simply need to implement a converter?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您面临的问题很可能与您的
ImageData
不是Stream
类型有关,而StremSource
属性实际上需要这种类型。假设的代码可能是这样的:
假设在本例中
ImageData
模型查看器属性的类型为Stream
。希望这有帮助。
The issue you face is most probably related to a fact that your
ImageData
is not type ofStream
, which is actually required by theStremSource
property.The hypothetical code, could be something like this:
Assuming that in this case
ImageData
model viewer property is of typeStream
.Hope this helps.