如何在ASP.NET中从数据库在aspx页面上显示图像 [英] How to display image on aspx page from database in ASP.NET

查看:184
本文介绍了如何在ASP.NET中从数据库在aspx页面上显示图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hye,我有一个包含USER_IMAGE,USER_NAME,USER_AGE列的数据库。

我想在aspx页面(前端)上显示用户的图像。我如何在aspx页面上显示图片。请帮我。顺便说一句,我在标签中显示USER_Name和USER_AGE。我的意思是我在字符串中获取USER_NAME和USER_AGE的值。然后我将该字符串传递给标签,我将在首页上显示。我怎么能用Image做同样的事情?



我尝试了什么:



现在我没有代码。顺便说一句,我已经在数据库中存储了图像。

解决方案

 <   asp:图像    ID   =  ImgProfilePic    runat   =  server      /  >  





  //  从数据库中获取图像,我希望它以二进制格式存储,因此它将返回一个字节数组 


< span class =code-keyword> byte [] imagem =( byte [])(dr [ IMG]);
string PROFILE_PIC = Convert.ToBase64String(imagem);

ImgProfilePic.ImageUrl = String .Format( data:image / jpg; base64,{0},PROFILE_PIC);


< pre lang =HTML> 
< asp:图片ID =ImgProfilePicrunat =server/>





  //  从数据库中获取图像,我希望它以二进制格式存储,因此它会返回一个字节数组 


byte [] imagem =( byte [])(dr [ IMG]);
string PROFILE_PIC = Convert.ToBase64String(imagem);

ImgProfilePic.ImageUrl = String .Format( data:image / jpg; base64,{0},PROFILE_PIC);


Hye, I have a database which contains columns of USER_IMAGE , USER_NAME, USER_AGE.
I want to display the image of the user on the aspx page (front end). How I can show the picture on the aspx page. Please help me. By the way i am displaying the USER_Name and USER_AGE in the label. I mean i am getting the values of USER_NAME and USER_AGE in string. Then i am passing that string to label, which i am showing on front page. How I can do same with Image??

What I have tried:

Right now i have no code. By the way i have stored images in the database.

解决方案

<asp:Image ID="ImgProfilePic" runat="server"  />



// Get your image from database, I hope it is stored in binary format, so it would return a byte array


byte[] imagem = (byte[])(dr["IMG"]);
string PROFILE_PIC = Convert.ToBase64String(imagem);

ImgProfilePic.ImageUrl = String.Format("data:image/jpg;base64,{0}", PROFILE_PIC); 


<pre lang="HTML">
 <asp:Image ID="ImgProfilePic" runat="server"  />



// Get your image from database, I hope it is stored in binary format, so it would return a byte array


byte[] imagem = (byte[])(dr["IMG"]);
string PROFILE_PIC = Convert.ToBase64String(imagem);

ImgProfilePic.ImageUrl = String.Format("data:image/jpg;base64,{0}", PROFILE_PIC); 


这篇关于如何在ASP.NET中从数据库在aspx页面上显示图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆