【发布时间】:2017-02-06 12:57:32
【问题描述】:
我必须按照以下要求制作移动应用程序
1- 加载图像,然后在其上绘制一些线条并将结果保存为 pdf 文件
2- 用户可以放大和缩小图像
3- 当他按下完成时,结果必须保存为 pdf 文件
4- 应用程序必须在 android 和 IOS 手机上运行
所以我选择使用 monaca 来使用 onsen (angularjs)(帮助我使用了一些有用的插件)
所以我将元素添加到我的 html 中
<ons-gesture-detector ng-pinchin= "onPinchInGesture()" ng-pinchout="onPinchOutGesture()" ng-dragleft="onDragLeftGesture()" ng-dragright="onDragRightGesture()" ng-dragdown="onDragDownGesture()" ng-dragup="onSwipeUpGesture()">
<canvas id="the-canvas" width="300px" height="400px" style="border: 1px solid blue;">
Your browser does not support the canvas element.
</canvas>
</ons-gesture-detector>
这里是java脚本函数
$scope.onPinchOutGesture = function(gesture) {
height = height + (2.5*(height/400));
width = width + (2.5*(width/300));
xPosition = xPosition - (2.5*(width/300));
yPosition = yPosition - (2.5*(width/300));
make_base(width , height, xPosition , yPosition);
};
$scope.onPinchInGesture = function(gesture) {
height = height - (2.5*(height/400));
width = width - (2.5*(width/300));
xPosition = xPosition + (2.5*(width/300));
yPosition = yPosition + (2.5*(width/300));
make_base(width , height, xPosition , yPosition);
};
$scope.onSwipeLeftGesture = function(gesture) {
xPosition = xPosition - (5*(width/300));
make_base(width , height, xPosition , yPosition);
};
$scope.onSwipeRightGesture = function(gesture) {
xPosition = xPosition + (5*(width/300));
make_base(width , height, xPosition , yPosition);
};
$scope.onSwipeDownGesture= function(gesture) {
yPosition = yPosition + (5*(height/400));
make_base(width , height, xPosition , yPosition);
};
$scope.onSwipeUpGesture= function(gesture) {
yPosition = yPosition - (5*(height/400));
make_base(width , height, xPosition , yPosition);
};
当我尝试放大特定部分时图像变大而不关注该部分的问题
所以我必须先放大然后寻找想要的部分
添加
function make_base(x , y, xPos, yPos){
width = x;
height = y;
xPosition = xPos;
yPosition = yPos;
var canvas = document.getElementById('the-canvas'),
context = canvas.getContext('2d');
base_image = new Image();
base_image.src =image path;
base_image.onload = function(){
context.clearRect(0, 0, canvas.width, canvas.height);
context.drawImage(base_image, xPosition, yPosition, x, y);
};
}
【问题讨论】:
标签: javascript android angularjs gesture