2017-04-01 11 views
0

画像が読み込まれたときキャンバス上で画像を回転しようとしていますが、表示されず、JavaScriptエラーも発生しません。JSキャンバス画像回転オンロード

ここのコードです:

function drawImage(pictureId, direction, ctx, posX, posY) { 
    var image = document.createElement("img"); 
    //i set the image src here 
    image.onload = function() {     
       drawRotated(image, direction, posX, posY); 
      } 
     } 
    function drawRotated(image, direction, posX, posY) { 
      ctx.save(); 
      ctx.rotate((direction*90)*(Math.PI/180));        
      ctx.drawImage(image, posX, posY); 
      ctx.restore(); 
    } 
+0

回しは、原点を中心に回転します。 90度回転すると、イメージはキャンバスの外側に完全に描画されます。あなたは 'rotate()'コールの前に 'context.translate(canvas.width/2、canvas.height/2);'などのように使ってみましたか?これにより、回転の原点が変更されます。 –

+0

Related [stackoverflow question](http://stackoverflow.com/questions/17411991/html5-canvas-rotate-image)。 –

+0

ありがとう、おい!それは本当にキャンバスの外でした。 :) – rckz

答えて

-1
<div class="avatar"> 
    <img class="img-responsive profile-img" ng-if="jc.profile.get('image')" ng-src="{{jc.profile.get('image')}}"> 
    <img class="img-responsive profile-img" ng-if="!jc.profile.get('image')" src="assets/images/man.png"> 
</div> 

VARデルタ= 0

this.rotateImage = function() { 
     if (this.user.get('imageRotation')) 
      delta = parseInt(this.user.get('imageRotation')) 
     delta += 90 
     delta = delta % 360 
     document.getElementById("image").style.webkitTransform = "rotate(" + delta + "deg)"; 
     return delta 
    } 


this.user = User; 
if (this.user.get('imageRotation') && $location.$$path.toString().includes('/user/')) 
    onLoadRotateImage(this.user.get('imageRotation')) 
// tools 
this.tools = User.tools; 
+0

コードの残りの部分をフォーマットしてください。 – WhatsThePoint

関連する問題