如何使用 javascript 在 smartface,io IDE 中旋转此图像?
How do I rotate this image in the smartface,io IDE using javascript?
我需要此图像在按下按钮时向左旋转 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
});
SMF.Bitmap
has static functions for image processing. 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%"
});
我需要此图像在按下按钮时向左旋转 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
});
SMF.Bitmap
has static functions for image processing. 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%"
});