简体   繁体   English

ASP.NET 4.0 C#会员用户图像

[英]Asp.net 4.0 c# membership user image

What I want to extract from the database is the UserImage in the table aspnet_Users but how do I extract it? 我想从数据库中提取的是表aspnet_Users中的UserImage,但是如何提取它呢?

I know when I want to extract the username its simply just by 我知道当我想提取用户名时

if (User.Identity.IsAuthenticated)
{
    lblUserName.Text = User.Identity.Name;
}

And how do I convert an image to byte[]? 以及如何将图像转换为byte []?

Or can I simply just add a new column and how will i be able to extract that 1? 或者我可以只添加一个新列,然后如何提取该列?

My advise will be for to use profiles to store unique information per user in your case it is an image path but store image file may be on CDN and your second question : And how do I convert an image to byte[]? 我的建议是,如果您使用配置文件来存储每个用户的唯一信息,则它是一个图像路径,但存储图像文件可能位于CDN上,您的第二个问题是: 如何将图像转换为byte []?

    System.Drawing.Image userImage = new Bitmap(ImagePath);

    System.IO.MemoryStream imageMemoryStream = new MemoryStream();

    userImage.Save(imageMemoryStream, System.Drawing.Imaging.ImageFormat.Jpeg);

    byte[] ImageByteArray = imageMemoryStream.ToArray();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM