MVC EF将位图插入表中 [英] MVC EF Insert bitmap into table

查看:98
本文介绍了MVC EF将位图插入表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编辑后,此代码生成位图并将其写入hdd文件。如何在我的数据库中保存?



After an edit, this code generates a bitmap and writes it to a hdd file. How do I save this in my db?

//   first   save the edit data  
Actionresult Edit (Lot Lot)   
{    remove scaffold code for clarity
db.SaveChanges();
// create a new image to replace image currently in db.  
Bitmap mybmp = new Bitmap(400, 20);  
Graphics g = Graphics.FromImage(mybmp);  
g.DrawRectangle(Pens.Black, 0, 0, 400, 20);  
SolidBrush b = new SolidBrush(Color.OldLace);  
g.FillRectangle(b, 0, 0, 400, 20);  
// write a test file to confirm this is ok   ------it works  
mybmp.Save("C:\\temp\\lot1.bmp",System.Drawing.Imaging.ImageFormat.Gif);

//  add code here to save image to Lot table field TaskImage  here
db.SaveChanges();
}





我的班级:





My Class:

public class Lot
{
public int LotID { get; set; }
public byte?[] TaskImage { get; set; }
}

推荐答案

在C#中需要一个不安全的块来访问图像的数据。或者使用File.ReadAllyBytes从刚刚保存它的硬盘驱动器中读取字节数组。 EF并不关心您的数据类型。
You need an unsafe block in C# to access the data of the image. Or use File.ReadAllyBytes to read the byte array from the hard drive where you just saved it. EF does not care what your data type is.


这篇关于MVC EF将位图插入表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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