| 1 |
<!DOCTYPE html> |
| 2 |
<html> |
| 3 |
<head> |
| 4 |
<title>Scale and translate image test</title> |
| 5 |
<style> |
| 6 |
|
| 7 |
body { |
| 8 |
text-align: center |
| 9 |
} |
| 10 |
|
| 11 |
</style> |
| 12 |
|
| 13 |
<script> |
| 14 |
|
| 15 |
function draw() { |
| 16 |
var ctx = document.getElementById('c').getContext('2d'); |
| 17 |
var s = .25; |
| 18 |
var w = 608 / 2; |
| 19 |
var h = 380 / 2; |
| 20 |
|
| 21 |
ctx.save(); |
| 22 |
ctx.translate(w, 0); |
| 23 |
ctx.scale(s, s); |
| 24 |
ctx.drawImage(img, 0, 0, w / s, h / s); |
| 25 |
ctx.restore(); |
| 26 |
|
| 27 |
ctx.save(); |
| 28 |
ctx.translate(w, 0); |
| 29 |
ctx.scale(-s, s); |
| 30 |
ctx.drawImage(img, 0, 0, w / s, h / s); |
| 31 |
ctx.restore(); |
| 32 |
|
| 33 |
ctx.save(); |
| 34 |
ctx.translate(w, 2 * h); |
| 35 |
ctx.scale(s, -s); |
| 36 |
ctx.drawImage(img, 0, 0, w / s, h / s); |
| 37 |
ctx.restore(); |
| 38 |
|
| 39 |
ctx.save(); |
| 40 |
ctx.translate(w, 2 * h); |
| 41 |
ctx.scale(-s, -s); |
| 42 |
ctx.drawImage(img, 0, 0, w / s, h / s); |
| 43 |
ctx.restore(); |
| 44 |
}; |
| 45 |
|
| 46 |
var img = new Image; |
| 47 |
img.onload = draw; |
| 48 |
window.onload = function() { |
| 49 |
img.src = '../examples/ff.jpg'; |
| 50 |
}; |
| 51 |
|
| 52 |
</script> |
| 53 |
</head> |
| 54 |
<body> |
| 55 |
|
| 56 |
<canvas id=c width=608 height=380></canvas> |
| 57 |
|
| 58 |
</body> |
| 59 |
</html> |