将位图图像绑定到数据库时设置源属性

发布于 2024-12-29 04:07:04 字数 628 浏览 3 评论 0原文

我正在使用以下代码将数据库(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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

猛虎独行 2025-01-05 04:07:04

您面临的问题很可能与您的 ImageData 不是 Stream 类型有关,而 StremSource 属性实际上需要这种类型。

假设的代码可能是这样的:

Byte[] imagesBytes = GetBytesOfImageFromDB();
ImageData= new MemoryStream(imagesBytes); 

假设在本例中 ImageData 模型查看器属性的类型为 Stream

希望这有帮助。

The issue you face is most probably related to a fact that your ImageData is not type of Stream, which is actually required by the StremSource property.

The hypothetical code, could be something like this:

Byte[] imagesBytes = GetBytesOfImageFromDB();
ImageData= new MemoryStream(imagesBytes); 

Assuming that in this case ImageData model viewer property is of type Stream.

Hope this helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文