0
Ich nehme Bildeingabe vom Benutzer, dann Größenanpassung und zeigt es auf einer Leinwand. Hier ist die Code-Größe Bild in html5 Canvas
HTML-
<form class="cmxform">
<input type='file' id="Photo" />
<canvas id="canvas" width="300" height="200"></canvas>
</form>
JavaScript-
$("#Photo").change(function (e) {
var ctx = document.getElementById('canvas').getContext('2d');
var img = new Image();
img.src = URL.createObjectURL(e.target.files[0]);
img.onload = function() {
ctx.drawImage(img, 0, 0, img.width, img.height, // source rectangle
0, 0, canvas.width, canvas.height); // destination rectangle
}
});
Aber hier verliere ich das Seitenverhältnis. Gibt es einen Weg, es zu tun?
UPDATE-
ich die Antwort von this sa question haben -
Soll das Bild wie CSS-Hintergrundgröße 'contain' oder' cover' wirken – haxxxton