哪个数据类型应该用于编辑器和放大器;文件和图片浏览 [英] Which DataType should be used for Editor & File and image browser
问题描述
哪个数据类型,应在MSSQL数据库MVC应用程序为以下字段作为下列组件使用? http://demos.telerik.com/aspnet-mvc/editor/index
Which datatype should be used in MSSQL database with an MVC application for the following fields as on the following components? http://demos.telerik.com/aspnet-mvc/editor/index
- 编辑器和放大器;文件
- 图像浏览器
推荐答案
在我的应用程序sotre形象base64string因此,为nvarchar(max)是我使用的数据类型。这样做的advangage是,你可以在JSON对象从或网站通过based64String形象。
In my application I sotre image as base64string hence, nvarchar(max) is the data type i used. The advangage of this is that you can pass based64String image in JSON object from or to website.
要图像转换为based64string
To convert image to based64string
public static string ToBased64String(this Image image, ImageFormat format)
{
using (MemoryStream ms = new MemoryStream())
{
image.Save(ms, format);
byte[] imageBytes = ms.ToArray();
string based64String = Convert.ToBased64String(imageBytes);
return based64String;
}
}
那么你可以打电话给你的方法是这样
then you can call your method like this
image.ToBased64String
要based64String转换为图片
To convert based64String to image
public static ImageFromBased64String(string based64Image, string path)
{
Image image = null;
var bytes = Convert.FromBased64String(based64String);
using (var fileStream = new FileStream(path, FileMode.Create))
{
fileStream.Write(bytes, 0, bytes.Length);
fileStream.Flush();
image = Image.FromStream(fileStream, true);
return image;
}
}
这篇关于哪个数据类型应该用于编辑器和放大器;文件和图片浏览的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!