public Photo GetPhoto(int id) { var photo = db.Photos.FirstOrDefault(x => x.Id == id); using (var ms = new MemoryStream(photo.Image)) { var bmp = new Bitmap(ms); var scaled = new Bitmap(bmp, new Size(bmp.Width / 2, bmp.Height / 2)); photo.Image = PreprocessingHelper.ToByteArray(scaled, ImageFormat.Jpeg); return(photo); } }
/// <summary> /// source code : modified from https://www.codeproject.com/Articles/884518/Csharp-Optical-Marks-Recognition-OMR-Engine-a-Mar /// </summary> public static bool[] GetBinaryScore(Bitmap slice, int OMCount, int sheetWhite, bool overrideWhite) { //make grayscale Grayscale gsf = new Grayscale(0.2989, 0.5870, 0.1140); slice = gsf.Apply(slice); //initialize members Rectangle[] cropRects = new Rectangle[OMCount]; Bitmap[] marks = new Bitmap[OMCount]; bool[] answers = new bool[OMCount]; //sub-devide line into options count (horizontal only) for (int i = 0; i < OMCount; i++) { cropRects[i] = new Rectangle(i * slice.Width / OMCount, 0, slice.Width / OMCount, slice.Height); } //the user specified that the line is actually multiple o Marks. lets crop them for (int i = 0; i < OMCount; i++) { marks[i] = new Bitmap(cropRects[i].Width, cropRects[i].Height); using (Graphics g = Graphics.FromImage(marks[i])) { g.DrawImage(slice, new Rectangle(0, 0, marks[i].Width, marks[i].Height), cropRects[i], GraphicsUnit.Pixel); } } if (!overrideWhite) { sheetWhite = PreprocessingHelper.GetWhiteLevel(new Bitmap(slice)); } for (int i = 0; i < OMCount; i++) { int temp = 0; temp = Math.Max(PreprocessingHelper.AvgColor((System.Drawing.Image)marks[i], sheetWhite / 2), 0); temp = (int)Math.Round(100 - (double)temp / (double)255 * 100D); //the lesser the temp var, the more sensative the detection becomes. This Value can be calibrated with further experimentation answers[i] = temp > 20; } return(answers); }