如何使用javascript在智能脸,io IDE中旋转此图像?

时间:2022-09-04 08:59:44

I need this image to, upon button press, rotate 90 degrees to the left, and upon a different button rotate 90 degrees to the right. here is my code. Any help would be greatly appreciated!!

我需要这个图像,按下按钮,向左旋转90度,然后在不同的按钮向右旋转90度。这是我的代码。任何帮助将不胜感激!!

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

1 个解决方案

#1


2  

SMF.Bitmap has static functions for image processing. rotate function will help you about your question.

SMF.Bitmap具有用于图像处理的静态函数。旋转功能将帮助您解决您的问题。

Here is a sample code for you:

以下是您的示例代码:

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%"
});

#1


2  

SMF.Bitmap has static functions for image processing. rotate function will help you about your question.

SMF.Bitmap具有用于图像处理的静态函数。旋转功能将帮助您解决您的问题。

Here is a sample code for you:

以下是您的示例代码:

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%"
});