显示数据库中的图像 [英] Display images from Database
本文介绍了显示数据库中的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好......
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[^]
这篇关于显示数据库中的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文