Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

228
Vistas
How to position my image on a canvas by positioning

I want to draw my image to the following anchored positions. How can I achieve this with Context2d::drawImage()? I purposefully placed it (0,0) btw.

anchors.right:  parent.right
anchors.top: parent.top
anchors.rightMargin: -10

    Canvas {
        anchors.fill: parent

        onPaint: {

            var ctx = getContext('2d');
            ctx.save();
            ctx.canvas.width = 160;
            ctx.canvas.height = 432;
            ctx.font = "18px Ubuntu";
            ctx.textAlign = "center";
            ctx.fillStyle = "#000000"

            const centerX = 10;
            const centerY = ctx.canvas.height / 2;
            const angle = Math.PI;
            const radius = 130
            ctx.fillStyle = "#000000"
            ctx.restore();
            
      

            ctx.save();
            ctx.drawImage(abcBar, 0, 0, abcBar.width, abcBar.height);
            console.log('loaded')
            ctx.restore();
}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

<!DOCTYPE html>
<html>
<body>

<canvas id="canvas"></canvas>
<div style="display:none;">
  <img id="source"
       src="https://picsum.photos/200"
       width="220" height="277">
</div>


<script>
const canvas = document.getElementById('canvas');
const ctx = canvas.getContext('2d');
const image = document.getElementById('source');

image.addEventListener('load', e => {
  //ctx.drawImage(image, 0, 0);
  ctx.drawImage(image, 33, 71, 104, 124, 21, 20, 87, 104);
  
//The source image is taken from the coordinates (33, 71), with a width of 104 
//and a height of 124. It is drawn to the canvas at (21, 20), where it is given      
//width of 87 and a height of 104.
});

</script>

</body>
</html>

enter image description here

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda