2017-01-09 29 views
1

我需要這個圖像,按下按鈕,向左旋轉90度,並在不同的按鈕向右旋轉90度。這是我的代碼。任何幫助將不勝感激!!如何使用javascript在smartface,io IDE中旋轉此圖像?

var pinWheel = new SMF.UI.Image({ 
    name :"Pin Wheel", 
    image : "assets://pin_wheel.png", 
    positionBackgroundImage : "CENTER", 
    top : "60%", 
    imageFillType: SMF.UI.ImageFillType.ASPECTFIT 
}); 

回答

2

SMF.Bitmap具有用於圖像處理的靜態功能。 rotate函數將幫助你解決你的問題。

這裏是你的示例代碼:

var img = new SMF.UI.Image({ 
    name: "img", 
    image: "smartface.png", 
    left: "15%", 
    top: "20%", 
    width: "70%", 
    height: "10%", 
    imageFillType: SMF.UI.ImageFillType.ASPECTFIT 
}); 

var btn = new SMF.UI.TextButton({ 
    name: "btn", 
    text: "Rotate!", 
    onPressed: function() { 
    var myImageUri = "smartface.png"; 
    var im = new SMF.Bitmap({ 
     imageUri: myImageUri, 
     onSuccess: function(e) { 
     im.rotate({ 
      angle: 90, 
      format: SMF.ImageFormat.PNG, 
      compressionRate: 0.7, 
      onSuccess: function(e) { 
      img.image = e.image; 
      }, 
      onError: function(e) { 
      alert("Error: " + e.message); 
      } 
     }); 
     }, 
     onError: function(e) { 
     alert("Error: " + e.message); 
     } 
    }); 
    }, 
    left: "15%", 
    top: "70%", 
    width: "70%", 
    height: "10%" 
}); 
+0

所以這個作品,這絕對是驚人的,但似乎有某種滯後或過渡,我想刪除的。我很感激迄今爲止所有的幫助,但是我還有什麼想法可以做到這一點? – Binary111

+0

@ Binary111 SMF.Bitmap函數異步工作,很可能這似乎是對你的滯後,我不認爲你可以爲它做任何事情。您可以顯示活動指標(如果旋轉花費很多時間)以獲得更好的用戶體驗。 – halit

+0

哦,好的,謝謝你的幫助!它是一款遊戲,所以我需要快速響應,但我認爲我可以添加之前旋轉過的新圖像,並刪除下面的圖像。 – Binary111