显示数据库中的图像

编程入门 行业动态 更新时间:2024-10-25 04:17:02
本文介绍了显示数据库中的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

大家好...... i得到了一个情况......在我的项目中,我需要在银灯页面上显示来自数据库的图像...... 所以我这样开发...... 我的XAML中的 ...

Hello everyone..... i got a situation... in my project, i need to show images from database on silver light pages... so i developed like this... in my XAML...

<Image Grid.Row="2" Margin="10" x:Name="image" Width="300" Height="200" HorizontalAlignment="Left"></Image>

和我的代码

and in my code

byte[] imageData = questions.ElementAt(Convert.ToInt16(x.Name)).Image; var bitmapImage = new BitmapImage(); bitmapImage.SetSource(new MemoryStream(imageData)); image.Source = bitmapImage;

但是图片没有渲染....任何人都可以帮助我

but the image is not rendering.... can anyone help me

推荐答案

嗨。如果我是你: 在DataBase中保存我的图像名称并创建一个这样的方法: public static BitmapImage GetBitMapImage(string relativeImage) { string imagePath = string.format(pack:// application:,,, / {0}; component /Images/{1}\",Assembly.GetExecutingAssembly().GetName().Name,relativeImage); URI uri = new URI(imagePath,UriKind.RelativeOrAbsolute ); 返回新的BitmapImage(uri); } imagePath中的图像是一个文件夹在您的应用程序中,所有图像都位于其中。 当您需要图像时。您必须写: Image myImage = new Image(); myImage.Source = GetBitMapImage(这个地方必须填充你的图像名称保存在DataBase中); 例如: myImage.source = GetBitMapImage(SaveIcon.png); 此操作非常有用,因为当您需要加载图像时。 祝你好运 Hi.If i was you: Save the name of my images in DataBase and Create a method like this: public static BitmapImage GetBitMapImage(string relativeImage) { string imagePath=string.format("pack://application:,,,/{0};component/Images/{1}",Assembly.GetExecutingAssembly().GetName().Name,relativeImage); URI uri=new URI(imagePath,UriKind.RelativeOrAbsolute); return new BitmapImage(uri); } "Images" in imagePath is a folder in your application that all of image is located in it. when you need to an image.you must write: Image myImage=new Image(); myImage.Source=GetBitMapImage(this place must populate with your image name that is saved in DataBase); for example : myImage.source=GetBitMapImage("SaveIcon.png"); this acction is useful because when you need your image is loaded. Good Luck

请参阅类似的主题:将图像加载到磁盘上但未包含在XAML上的项目中 [ ^ ] Refer similar thread: Loading images on disk but not included in the project on XAML[^]

更多推荐

显示数据库中的图像

本文发布于:2023-11-27 20:18:08,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1639457.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据库中   图像

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!