Click here to Skip to main content
15,887,477 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
After an edit, this code generates a bitmap and writes it to a hdd file. How do I save this in my db?

C#
//   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:

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

1 solution

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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900