Hallo, mit folgendem Code erstelle ich 2 Bilder, eines rein mit HTML, das zweite
dann mit JS im Canvas-Bereich. Warum ist das mit JS bearbeitete Bild nur teilweise und
vergrößert zu sehen? Ich gebe ja stets width und height an. (könnte ich auch noch bei drawImage, ändert aber nichts) Vielen Dank!
Browser: Firefox 48.0/Internet Explorer11
Code:
- - - Aktualisiert - - -
Ahh sorry, das canvas-Tag muss so aussehen:
Die Angaben nicht in CSS!
dann mit JS im Canvas-Bereich. Warum ist das mit JS bearbeitete Bild nur teilweise und
vergrößert zu sehen? Ich gebe ja stets width und height an. (könnte ich auch noch bei drawImage, ändert aber nichts) Vielen Dank!

Browser: Firefox 48.0/Internet Explorer11
Code:
HTML:
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Titel</title>
<script>
function drawCanvas()
{
var element = document.getElementById('canvas');
var img = new Image();
img.onload = function() {
if(element.getContext)
{
var context = element.getContext('2d');
context.drawImage(img,0,0);
}
}
img.src = "background.jpg";
}
</script>
</head>
<body>
<img id="stars" width="500" height="500" src="background.jpg" alt="background">
<canvas id="canvas" style="width: 500px; height: 500px; background-color: white;">
</canvas>
<script> drawCanvas() </script>
</body>
</html>
- - - Aktualisiert - - -
Ahh sorry, das canvas-Tag muss so aussehen:
HTML:
<canvas id="canvas" width="500" height="500"></canvas>
Zuletzt bearbeitet von einem Moderator: