关于img src动态生成图片


 <img id="J_MarkPaperIMG" style="width:800px;" src="/MarkingDistribution/GetMarkingDetailIMG?ExamStudentID=4987493652ad03b9&amp;TestPaperID=ede0faad462593d4&amp;TestPaperProblemID=f7ce519d686f4e85&amp;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");


        }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值