correct.jsp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508
  1. <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
  2. <%
  3. String path = request.getContextPath();
  4. String basePath = request.getScheme() + "://"
  5. + request.getServerName() + ":" + request.getServerPort()
  6. + path + "/";
  7. %>
  8. <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
  9. <%@page isELIgnored="false"%>
  10. <!DOCTYPE html>
  11. <head>
  12. <meta charset="UTF-8">
  13. <meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible">
  14. <meta name="viewport"
  15. content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no, width=device-width">
  16. <title></title>
  17. <link rel="stylesheet" type="text/css"
  18. href="${pageContext.request.contextPath}/css/correct.css" />
  19. <style>
  20. #background {
  21. cursor: url('${pageContext.request.contextPath}/img/cursor.png'), auto;
  22. }
  23. #annotated {
  24. background: url('${pageContext.request.contextPath}/img/annotated.png')
  25. no-repeat right;
  26. }
  27. .annotated:after {
  28. position: absolute;
  29. background: url('${pageContext.request.contextPath}/img/annotated.png');
  30. background-size: 100% 100%;
  31. background-repeat: no-repeat;
  32. content: '';
  33. width: 40px;
  34. height: 40px;
  35. bottom: 0;
  36. right: 0;
  37. }
  38. </style>
  39. </head>
  40. <body>
  41. <div class="header">
  42. <div class="img_button img_pencil active">
  43. <button id="pencil">
  44. </div>
  45. <div class="line"></div>
  46. <div class="color_select">
  47. <div id="color_fadeToggle">
  48. <ul class="color_list">
  49. <li data-value="#000000" style="background: #000000"></li>
  50. <li data-value="#424242" style="background: #424242"></li>
  51. <li data-value="#626262" style="background: #626262"></li>
  52. <li data-value="#9d9d95" style="background: #9d9d95"></li>
  53. <li data-value="#c7c7c7" style="background: #c7c7c7"></li>
  54. <li data-value="#efefef" style="background: #efefef"></li>
  55. <li data-value="#f7f7f7" style="background: #f7f7f7"></li>
  56. <li data-value="#ffffff" style="background: #ffffff"></li>
  57. <li data-value="#ff0000" style="background: #ff0000"></li>
  58. <li data-value="#ff9d00" style="background: #ff9d00"></li>
  59. <li data-value="#ffff00" style="background: #ffff00"></li>
  60. <li data-value="#00ff00" style="background: #00ff00"></li>
  61. <li data-value="#00ffff" style="background: #00ffff"></li>
  62. <li data-value="#0000ff" style="background: #0000ff"></li>
  63. <li data-value="#9d00ff" style="background: #9d00ff"></li>
  64. <li data-value="#ff00ff" style="background: #ff00ff"></li>
  65. <li data-value="#f7c7cf" style="background: #f7c7cf"></li>
  66. <li data-value="#ffebcb" style="background: #ffebcb"></li>
  67. <li data-value="#ffebcb" style="background: #ffebcb"></li>
  68. <li data-value="#d7efd7" style="background: #d7efd7"></li>
  69. <li data-value="#d3dbe7" style="background: #d3dbe7"></li>
  70. <li data-value="#cfe7f7" style="background: #cfe7f7"></li>
  71. <li data-value="#d3dbe7" style="background: #d3dbe7"></li>
  72. <li data-value="#e7d7df" style="background: #e7d7df"></li>
  73. <li data-value="#e79d9d" style="background: #e79d9d"></li>
  74. <li data-value="#ffc79d" style="background: #ffc79d"></li>
  75. <li data-value="#ffe79d" style="background: #ffe79d"></li>
  76. <li data-value="#b5d7a5" style="background: #b5d7a5"></li>
  77. <li data-value="#a5c7cf" style="background: #a5c7cf"></li>
  78. <li data-value="#9dc7ef" style="background: #9dc7ef"></li>
  79. <li data-value="#b5a5d7" style="background: #b5a5d7"></li>
  80. <li data-value="#d7a5bd" style="background: #d7a5bd"></li>
  81. <li data-value="#e76262" style="background: #e76262"></li>
  82. <li data-value="#f7ad6a" style="background: #f7ad6a"></li>
  83. <li data-value="#ffd762" style="background: #ffd762"></li>
  84. <li data-value="#95bd7a" style="background: #95bd7a"></li>
  85. <li data-value="#72a5ad" style="background: #72a5ad"></li>
  86. <li data-value="#6aaddf" style="background: #6aaddf"></li>
  87. <li data-value="#8d7ac7" style="background: #8d7ac7"></li>
  88. <li data-value="#c77aa5" style="background: #c77aa5"></li>
  89. <li data-value="#cf0000" style="background: #cf0000"></li>
  90. <li data-value="#e79538" style="background: #e79538"></li>
  91. <li data-value="#efc730" style="background: #efc730"></li>
  92. <li data-value="#6aa54a" style="background: #6aa54a"></li>
  93. <li data-value="#4a7a8d" style="background: #4a7a8d"></li>
  94. <li data-value="#385c7" style="background: #3885c7"></li>
  95. <li data-value="#624aa5" style="background: #624aa5"></li>
  96. <li data-value="#a54a7a" style="background: #a54a7a"></li>
  97. <li data-value="#9d0000" style="background: #9d0000"></li>
  98. <li data-value="#b56208" style="background: #b56208"></li>
  99. <li data-value="#bd9500" style="background: #bd9500"></li>
  100. <li data-value="#387a20" style="background: #387a20"></li>
  101. <li data-value="#104a5a" style="background: #104a5a"></li>
  102. <li data-value="#085295" style="background: #085295"></li>
  103. <li data-value="#301872" style="background: #301872"></li>
  104. <li data-value="#721842" style="background: #721842"></li>
  105. <li data-value="#620000" style="background: #620000"></li>
  106. <li data-value="#7a3800" style="background: #7a3800"></li>
  107. <li data-value="#285218" style="background: #285218"></li>
  108. <li data-value="#285218" style="background: #285218"></li>
  109. <li data-value="#083038" style="background: #083038"></li>
  110. <li data-value="#003062" style="background: #003062"></li>
  111. <li data-value="#20104a" style="background: #20104a"></li>
  112. <li data-value="#4a1030" style="background: #4a1030"></li>
  113. </ul>
  114. </div>
  115. </div>
  116. <input type="range" max="15" min="1" id="range" />
  117. <div class="line"></div>
  118. <div class="img_button img_empty">
  119. <button id="clear_canvas">
  120. </div>
  121. <div class="img_button img_save">
  122. <button id="save_canvas">
  123. </div>
  124. <div class="img_button img_download">
  125. <button id="download">
  126. </div>
  127. </div>
  128. <div class="sidebar_left">
  129. <ul class="img_select">
  130. <c:forEach var="i" begin="1" end="${correct_number}">
  131. <li id="img_${i}" class=""><img
  132. src="${pageContext.request.contextPath}/Document/correct/img/${correct}/${i}.png"
  133. id="annotated" />
  134. </form></li>
  135. </c:forEach>
  136. </ul>
  137. </div>
  138. <div class="main">
  139. <div class="correct">
  140. <div id="background"
  141. style="background-image:url('${pageContext.request.contextPath}/Document/correct/img/${correct}/1.png'); background-size: 100% 100%; background-repeat: no-repeat;">
  142. <canvas id="canvas"></canvas>
  143. </div>
  144. </div>
  145. </div>
  146. <script src="${pageContext.request.contextPath}/js/jquery-3.3.1.min.js"
  147. type="text/javascript" charset="utf-8"></script>
  148. <script src="${pageContext.request.contextPath}/js/correct.js"
  149. type="text/javascript" charset="utf-8"></script>
  150. <script type="text/javascript">
  151. //获取id为background的对象
  152. var background = document.getElementById("background")
  153. <c:forEach var="a" begin="1" end="${correct_number}">
  154. //a代表当前条目的变量名称
  155. $("#img_${a}")
  156. .click(
  157. function() {
  158. //获取批注的base64编码
  159. var image = new Image();
  160. image.src = canvas.toDataURL("image/png");//得到图片的BASE64码
  161. var abc = image.src
  162. //base64 编码中含有大量加号,而+在 URL 传递时会被当成空格
  163. var base64_ = abc.replace(/\+/g, '%2B');
  164. // 获取id为correct中的backgroundImage值
  165. var a = document.getElementById("background").style.backgroundImage;
  166. // 通过正则表达式得知当前正在批注的图片
  167. var str = a.match(/([^/]+).png/)[1];
  168. // 替换id为background对象的背景图片
  169. document.getElementById("background").style.cssText = "background-image: url(${pageContext.request.contextPath}/Document/correct/img/${correct}/${a}.png);background-size: 100% 100%;background-repeat: no-repeat;"
  170. // 通过ajax将获取到的base64以post方式传输到后台处理
  171. var xmlhttp;
  172. if (window.XMLHttpRequest) {
  173. // IE7+, Firefox, Chrome, Opera, Safari 浏览器执行代码
  174. xmlhttp = new XMLHttpRequest();
  175. } else {
  176. // IE6, IE5 浏览器执行代码
  177. xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  178. }
  179. xmlhttp.open("POST", "Encode", true);
  180. xmlhttp.setRequestHeader("Content-Type",
  181. "application/x-www-form-urlencoded");
  182. xmlhttp.send("img_name=" + str + "&base64="
  183. + base64_);
  184. //消除批注
  185. cvs.clearRect(0, 0, canvas.width, canvas.height);
  186. });
  187. </c:forEach>
  188. $(function() {
  189. var xmlhttp;
  190. if (window.XMLHttpRequest) {
  191. // IE7+, Firefox, Chrome, Opera, Safari 浏览器执行代码
  192. xmlhttp = new XMLHttpRequest();
  193. } else {
  194. // IE6, IE5 浏览器执行代码
  195. xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  196. }
  197. xmlhttp.open("POST", "Magic", true);
  198. xmlhttp.setRequestHeader("Content-Type",
  199. "application/x-www-form-urlencoded");
  200. xmlhttp.send("number=" + ${correct_number});
  201. });
  202. </script>
  203. </body>
  204. </html>
  205. <!--
  206. <head>
  207. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  208. <title>javascript结合html5 canvas实现的涂鸦板 - 分享JavaScript-sharejs.com</title>
  209. <meta name="Copyright" content="JavaScript分享网 http://www.sharejs.com/" />
  210. <meta name="description" content="javascript结合html5 canvas实现的涂鸦板,JavaScript分享网,js脚本,网页特效,网页模板,png图标,矢量图下载" />
  211. <meta content="JavaScript,分享,JavaScript代码,Ajax,jQuery,网页模板,PNG图标,矢量图" name="keywords" />
  212. </head>
  213. <body>
  214. <style>
  215. *{margin:0;padding:0;}
  216. .fa{width:740px;margin:0 auto;}
  217. .top{margin:20px 0;}
  218. .top input{width:25px;height:25px;border:1px solid #fff;border-radius:4px;background:#ddd;}
  219. .top .i1{background:#000000;}
  220. .top .i2{background:#FF0000;}
  221. .top .i3{background:#80FF00;}
  222. .top .i4{background:#00FFFF;}
  223. .top .i5{background:#808080;}
  224. .top .i6{background:#FF8000;}
  225. .top .i7{background:#408080;}
  226. .top .i8{background:#8000FF;}
  227. .top .i9{background:#CCCC00;}
  228. #canvas{background:#eee;cursor:default;}
  229. .font input{font-size:14px;}
  230. .top .grea{background:#aaa;}
  231. </style>
  232. <body>
  233. <div class="fa">
  234. <div class="top">
  235. <div id="color">
  236. 请选择画笔颜色:
  237. <input class="i1" type="button" value="" />
  238. <input class="i2" type="button" value="" />
  239. <input class="i3" type="button" value="" />
  240. <input class="i4" type="button" value="" />
  241. <input class="i5" type="button" value="" />
  242. <input class="i6" type="button" value="" />
  243. <input class="i7" type="button" value="" />
  244. <input class="i8" type="button" value="" />
  245. <input class="i9" type="button" value="" />
  246. </div>
  247. <div class="font" id="font">
  248. 请选择画笔的宽度:
  249. <input type="button" value="细" />
  250. <input type="button" value="中" class="grea"/>
  251. <input type="button" value="粗" />
  252. </div>
  253. <div>
  254. <span id="error">如果有错误,请使用橡皮擦:</span>
  255. <input id="eraser" style="width:60px;font-size:14px;"type="button" value="橡皮擦" > </input>
  256. </div>
  257. <input id="clear" type="button" value="清除画布" style="width:80px;"/>
  258. <input id="revocation" type="button" value="撤销" style="width:80px;"/>
  259. <input id="imgurl" type="button" value="导出图片路径" style="width:85px;"/>
  260. </div>
  261. <canvas id="canvas" width="740" height="420">您的浏览器不支持 canvas 标签</canvas>
  262. <div id="div1"></div>
  263. </div>
  264. <div id="html">
  265. </div>
  266. <script>
  267. (function(){
  268. var paint={
  269. init:function()
  270. {
  271. this.load();
  272. },
  273. load:function()
  274. {
  275. this.x=[];//记录鼠标移动是的X坐标
  276. this.y=[];//记录鼠标移动是的Y坐标
  277. this.clickDrag=[];
  278. this.lock=false;//鼠标移动前,判断鼠标是否按下
  279. this.isEraser=false;
  280. //this.Timer=null;//橡皮擦启动计时器
  281. //this.radius=5;
  282. this.storageColor="#000000";
  283. this.eraserRadius=15;//擦除半径值
  284. this.color=["#000000","#FF0000","#80FF00","#00FFFF","#808080","#FF8000","#408080","#8000FF","#CCCC00"];//画笔颜色值
  285. this.fontWeight=[2,5,8];
  286. this.$=function(id){return typeof id=="string"?document.getElementById(id):id;};
  287. this.canvas=this.$("canvas");
  288. if (this.canvas.getContext) {
  289. } else {
  290. alert("您的浏览器不支持 canvas 标签");
  291. return;
  292. }
  293. this.cxt=this.canvas.getContext('2d');
  294. this.cxt.lineJoin = "round";//context.lineJoin - 指定两条线段的连接方式
  295. this.cxt.lineWidth = 5;//线条的宽度
  296. this.iptClear=this.$("clear");
  297. this.revocation=this.$("revocation");
  298. this.imgurl=this.$("imgurl");//图片路径按钮
  299. this.w=this.canvas.width;//取画布的宽
  300. this.h=this.canvas.height;//取画布的高
  301. this.touch =("createTouch" in document);//判定是否为手持设备
  302. this.StartEvent = this.touch ? "touchstart" : "mousedown";//支持触摸式使用相应的事件替代
  303. this.MoveEvent = this.touch ? "touchmove" : "mousemove";
  304. this.EndEvent = this.touch ? "touchend" : "mouseup";
  305. this.bind();
  306. },
  307. bind:function()
  308. {
  309. var t=this;
  310. /*清除画布*/
  311. this.iptClear.onclick=function()
  312. {
  313. t.clear();
  314. };
  315. /*鼠标按下事件,记录鼠标位置,并绘制,解锁lock,打开mousemove事件*/
  316. this.canvas['on'+t.StartEvent]=function(e)
  317. {
  318. var touch=t.touch ? e.touches[0] : e;
  319. var _x=touch.clientX - touch.target.offsetLeft;//鼠标在画布上的x坐标,以画布左上角为起点
  320. var _y=touch.clientY - touch.target.offsetTop;//鼠标在画布上的y坐标,以画布左上角为起点
  321. if(t.isEraser)
  322. {
  323. /*
  324. t.cxt.globalCompositeOperation = "destination-out";
  325. t.cxt.beginPath();
  326. t.cxt.arc(_x, _y,t.eraserRadius, 0, Math.PI * 2);
  327. t.cxt.strokeStyle = "rgba(250,250,250,0)";
  328. t.cxt.fill();
  329. t.cxt.globalCompositeOperation = "source-over";
  330. */
  331. t.resetEraser(_x,_y,touch);
  332. }else
  333. {
  334. t.movePoint(_x,_y);//记录鼠标位置
  335. t.drawPoint();//绘制路线
  336. }
  337. t.lock=true;
  338. };
  339. /*鼠标移动事件*/
  340. this.canvas['on'+t.MoveEvent]=function(e)
  341. {
  342. var touch=t.touch ? e.touches[0] : e;
  343. if(t.lock)//t.lock为true则执行
  344. {
  345. var _x=touch.clientX - touch.target.offsetLeft;//鼠标在画布上的x坐标,以画布左上角为起点
  346. var _y=touch.clientY - touch.target.offsetTop;//鼠标在画布上的y坐标,以画布左上角为起点
  347. if(t.isEraser)
  348. {
  349. //if(t.Timer)clearInterval(t.Timer);
  350. //t.Timer=setInterval(function(){
  351. t.resetEraser(_x,_y,touch);
  352. //},10);
  353. }
  354. else
  355. {
  356. t.movePoint(_x,_y,true);//记录鼠标位置
  357. t.drawPoint();//绘制路线
  358. }
  359. }
  360. };
  361. this.canvas['on'+t.EndEvent]=function(e)
  362. {
  363. /*重置数据*/
  364. t.lock=false;
  365. t.x=[];
  366. t.y=[];
  367. t.clickDrag=[];
  368. clearInterval(t.Timer);
  369. t.Timer=null;
  370. };
  371. this.revocation.onclick=function()
  372. {
  373. t.redraw();
  374. };
  375. this.changeColor();
  376. this.imgurl.onclick=function()
  377. {
  378. t.getUrl();
  379. };
  380. /*橡皮擦*/
  381. this.$("eraser").onclick=function(e)
  382. {
  383. t.isEraser=true;
  384. t.$("error").style.color="red";
  385. t.$("error").innerHTML="您已使用橡皮擦!";
  386. };
  387. },
  388. movePoint:function(x,y,dragging)
  389. {
  390. /*将鼠标坐标添加到各自对应的数组里*/
  391. this.x.push(x);
  392. this.y.push(y);
  393. this.clickDrag.push(y);
  394. },
  395. drawPoint:function(x,y,radius)
  396. {
  397. for(var i=0; i < this.x.length; i++)//循环数组
  398. {
  399. this.cxt.beginPath();//context.beginPath() , 准备绘制一条路径
  400. if(this.clickDrag[i] && i){//当是拖动而且i!=0时,从上一个点开始画线。
  401. this.cxt.moveTo(this.x[i-1], this.y[i-1]);//context.moveTo(x, y) , 新开一个路径,并指定路径的起点
  402. }else{
  403. this.cxt.moveTo(this.x[i]-1, this.y[i]);
  404. }
  405. this.cxt.lineTo(this.x[i], this.y[i]);//context.lineTo(x, y) , 将当前点与指定的点用一条笔直的路径连接起来
  406. this.cxt.closePath();//context.closePath() , 如果当前路径是打开的则关闭它
  407. this.cxt.stroke();//context.stroke() , 绘制当前路径
  408. }
  409. },
  410. clear:function()
  411. {
  412. this.cxt.clearRect(0, 0, this.w, this.h);//清除画布,左上角为起点
  413. },
  414. redraw:function()
  415. {
  416. /*撤销*/
  417. this.cxt.restore();
  418. },
  419. preventDefault:function(e){
  420. /*阻止默认*/
  421. var touch=this.touch ? e.touches[0] : e;
  422. if(this.touch)touch.preventDefault();
  423. else window.event.returnValue = false;
  424. },
  425. changeColor:function()
  426. {
  427. /*为按钮添加事件*/
  428. var t=this,iptNum=this.$("color").getElementsByTagName("input"),fontIptNum=this.$("font").getElementsByTagName("input");
  429. for(var i=0,l=iptNum.length;i<l;i++)
  430. {
  431. iptNum[i].index=i;
  432. iptNum[i].onclick=function()
  433. {
  434. t.cxt.save();
  435. t.cxt.strokeStyle = t.color[this.index];
  436. t.storageColor=t.color[this.index];
  437. t.$("error").style.color="#000";
  438. t.$("error").innerHTML="如果有错误,请使用橡皮擦:";
  439. t.cxt.strokeStyle = t.storageColor;
  440. t.isEraser=false;
  441. }
  442. }
  443. for(var i=0,l=fontIptNum.length;i<l;i++)
  444. {
  445. t.cxt.save();
  446. fontIptNum[i].index=i;
  447. fontIptNum[i].onclick=function()
  448. {
  449. t.changeBackground(this.index);
  450. t.cxt.lineWidth = t.fontWeight[this.index];
  451. t.$("error").style.color="#000";
  452. t.$("error").innerHTML="如果有错误,请使用橡皮擦:";
  453. t.isEraser=false;
  454. t.cxt.strokeStyle = t.storageColor;
  455. }
  456. }
  457. },
  458. changeBackground:function(num)
  459. {
  460. /*添加画笔粗细的提示背景颜色切换,灰色为当前*/
  461. var fontIptNum=this.$("font").getElementsByTagName("input");
  462. for(var j=0,m=fontIptNum.length;j<m;j++)
  463. {
  464. fontIptNum[j].className="";
  465. if(j==num) fontIptNum[j].className="grea";
  466. }
  467. },
  468. getUrl:function()
  469. {
  470. this.$("html").innerHTML=this.canvas.toDataURL();
  471. },
  472. resetEraser:function(_x,_y,touch)
  473. {
  474. /*使用橡皮擦-提醒*/
  475. var t=this;
  476. //this.cxt.lineWidth = 30;
  477. /*source-over 默认,相交部分由后绘制图形的填充(颜色,渐变,纹理)覆盖,全部浏览器通过*/
  478. t.cxt.globalCompositeOperation = "destination-out";
  479. t.cxt.beginPath();
  480. t.cxt.arc(_x, _y, t.eraserRadius, 0, Math.PI * 2);
  481. t.cxt.strokeStyle = "rgba(250,250,250,0)";
  482. t.cxt.fill();
  483. t.cxt.globalCompositeOperation = "source-over"
  484. }
  485. };
  486. paint.init();
  487. })();
  488. </script>
  489. <div style="clear:both"></div>
  490. </body>
  491. </html>
  492. -->