locked
URGENT help with canvas context setTransform RRS feed

  • Question

  • Guys i have this annoying problem when rendering a tranformed image to a canvas:
    ---------------
    base_image.src = temp.src;

    var matrix = temp.style.msTransform;
    matrix = matrix.replace("matrix(", "");
    matrix = matrix.replace(")", "");
    var array = matrix.split(",");
    base_image.onload = function () {
           canvasCtx.save();
           canvasCtx.setTransform(array[0], array[1], array[2], array[3], array[4], array[5]);
           canvasCtx.drawImage(base_image, 0, 0);
           canvasCtx.restore();

    -------------------
    The problem only happens when i rotate or scale the image.. when it's not rotated or scaled it is transfered at the exact position as it was as an image above the canvas.. BUT when i rotate or scale it is not at the right position. always some pixels to the right/left and sime pixels to top/bottom. always shifted and it depends of how much i scaled or rotated.
    How to fix it?
    Thanks,

    Alan.

    Thursday, October 11, 2012 1:34 AM

Answers

  • Hi Alan,

    Depending on how you set up your transform the rotation and scaling can affect the translation and vice versa.

    Can you please provide a bit more information about the problem? Can you provide enough sample code to reproduce the problem and a more precise description of how the actual results differ from the expected results? An annotated screenshot would help.

    --Rob

    • Marked as answer by Song Tian Friday, November 9, 2012 6:32 AM
    Friday, October 12, 2012 6:37 AM
    Moderator

All replies

  • boy this forum has been useless lately...
    Thursday, October 11, 2012 10:29 PM
  • Hi Alan,

    Depending on how you set up your transform the rotation and scaling can affect the translation and vice versa.

    Can you please provide a bit more information about the problem? Can you provide enough sample code to reproduce the problem and a more precise description of how the actual results differ from the expected results? An annotated screenshot would help.

    --Rob

    • Marked as answer by Song Tian Friday, November 9, 2012 6:32 AM
    Friday, October 12, 2012 6:37 AM
    Moderator