2
特別是我有這樣的例子,但它似乎不工作:如何使用HTML5縮放ImageData?
<!DOCTYPE html>
<html>
<body>
<canvas id="myCanvas" width="300" height="150" style="border:1px solid #d3d3d3;">
your browser does not support the canvas tag </canvas>
<canvas id="myCanvas2" width="300" height="150" style="border:1px solid #d3d3d3;">
your browser does not support the canvas tag </canvas>
<script type="text/javascript">
var c=document.getElementById("myCanvas");
var ctx=c.getContext("2d");
var c2=document.getElementById("myCanvas2");
var ctx2=c2.getContext("2d");
ctx.strokeRect(5,5,25,15);
var imageData = ctx.getImageData(0,0,c.width, c.height);
ctx2.putImageData(imageData, 100, 100);
ctx2.scale(2,2);
</script>
</body>
</html>
不應該RECT得到縮放在第二畫布?
這是行不通的。 – Olivier 2014-05-08 20:39:00
ImageData是一個原始像素數組,因此不會受到應用於畫布的縮放/轉換的影響 - 隻影響發送到畫布的新繪圖。您需要將數據複製到新的圖像或畫布,可以根據比例進行調整。請參閱http://stackoverflow.com/questions/24429830/html5-canvas-how-to-change-putimagedata-scale – brichins 2016-06-03 15:18:23