<img id="J_MarkPaperIMG" style="width:800px;" src="/MarkingDistribution/GetMarkingDetailIMG?ExamStudentID=4987493652ad03b9&TestPaperID=ede0faad462593d4&TestPaperProblemID=f7ce519d686f4e85&Index=0">
public ActionResult GetMarkingDetailIMG(string TestPaperID, string TestPaperProblemID, string ExamStudentID,int Index)
{byte[] bytes = new byte[] { };
//取出试题
var testPaperProblemIDArr = TestPaperProblemID.Split('|');
//判断是否已经评
var QuestionScore = QuestionScoreService.Find(ExamStudentID, testPaperProblemIDArr[0], TestPaperID).FirstOrDefault();
if (QuestionScore != null && System.IO.File.Exists(Server.MapPath(Constant.UPLOAD_PATH + "/" + QuestionScore.ID)))
{
Bitmap bitmap = new Bitmap(Server.MapPath(Constant.UPLOAD_PATH + "/" + QuestionScore.ID));
MemoryStream ms = new MemoryStream();
bitmap.Save(ms, ImageFormat.Jpeg);
bytes = new byte[ms.Length];
ms.Seek(0, SeekOrigin.Begin);
ms.Read(bytes, 0, Convert.ToInt32(ms.Length));
ms.Close();
ms.Dispose();
bitmap.Dispose();
}
else
{
var testPaperAnswerSheetList = TestPaperAnswerSheetService.Find(new ConditionCollection() {
new Condition("TestPaperProblemID",testPaperProblemIDArr[0]),
new Condition("TestPaperID",TestPaperID)
}, new SortOrderCollection { new SortOrder("PageNum", true) });
//加载位置
TestPaperAnswerSheet testPaperAnswerSheet = null;
if (Index == 10)
{
testPaperAnswerSheet = testPaperAnswerSheetList[0];
}
else if (testPaperAnswerSheetList.Count > 0)
{
testPaperAnswerSheet = testPaperAnswerSheetList[Index];
}
//拿到答题卡类型
TestPaper testPaper = TestPaperService.FindOnly(new TestPaper() { ID = TestPaperID });
if (testPaperAnswerSheet != null)
{
var PageNum = testPaperAnswerSheet.PageNum;
if (testPaper.PaperType.Equals("A3"))
{
PageNum = PageNum % 2 == 0 ? PageNum / 2 : PageNum / 2 + 1;
}
//var studentAnswerSheet = StudentAnswerSheetService.Find(new ConditionCollection() {
// new Condition("ExamStudentID",ExamStudentID),
// new Condition("PageNum",PageNum)
//}, null).FirstOrDefault();
StudentAnswerSheet studentAnswerSheet = StudentAnswerSheetService.FindDataByExamStudentID(ExamStudentID, PageNum, TestPaperID);
if (Index == 10)
{
return Json(studentAnswerSheet.ID, JsonRequestBehavior.AllowGet);
}
//判断是否存在数据
if (studentAnswerSheet != null)
{
string path = Server.MapPath("/Upload/Marking/") + studentAnswerSheet.ID;
if (System.IO.File.Exists(path))
{
//加载位置
Bitmap bitmap = new Bitmap(path);
Image<Gray, byte> image = new Image<Gray, byte>(bitmap);
Double DPI = 8;
Double Pic_Left = testPaperAnswerSheet.Left;
//如果答题卡纸张类型为A3 同时页数为2的倍数则题目加上一张A4宽度
if (testPaper.PaperType.Equals("A3") && testPaperAnswerSheet.PageNum % 2 == 0)
{
Pic_Left += 209.7;
}
Mat rotated = new Mat(image.Mat, new Rectangle(Convert.ToInt32(Pic_Left * DPI), Convert.ToInt32(testPaperAnswerSheet.Top * DPI), Convert.ToInt32(testPaperAnswerSheet.Width * DPI), Convert.ToInt32(testPaperAnswerSheet.Height * DPI)));
MemoryStream ms = new MemoryStream();
var b = rotated.Bitmap;
b.Save(ms, ImageFormat.Jpeg);
bytes = ms.GetBuffer();
ms.Close();
ms.Dispose();
bitmap.Dispose();
}
}
}
}
return File(bytes, "image/jpeg");
}