/*
软件作者:https://xuhss.com/oxox/pro
*/
"ui";
/**
*作者QQ: 1811588980
*完成时间: 2019年5月19日 下午4:22:57
*备注: 暂无备注
**/
ui.layout(
<vertical>
<canvas id="canvas" layout_weight="1"/>
<button id="openImage" text="打开图片"/>
<button id="imageSave" text="保存处理后图片"/>
</vertical>
);
threads.start(function() {
//console.show();
});
var imagesPath = new Array;
thread = threads.start(function() {
sleep(1000);
getPhotosInfo(25, imagesPath);
});
var storage = storages.create("图片剪切");
var imagePath = storage.get("imagePath");
events.on("exit", function() {
storage.put("imagePath", imagePath);
});
var MainImg = 加载图片(imagePath);
ui.openImage.click(function() {
threads.start(function() {
switch (dialogs.singleChoice("选择方式", ["媒体库", "本机文件"])) {
case 0:
媒体库选择(function(path) {
var img = MainImg;
MainImg = 加载图片(path);
if (MainImg) {
imageRect.set(new android.graphics.RectF(0, 0, MainImg.getWidth(), MainImg.getHeight()));
canvasMatrix.setRectToRect(imageRect, canvasRect, android.graphics.Matrix.ScaleToFit.CENTER);
};
if (img) {
img.recycle();
};
});
break;
case 1:
选择图片(function(path) {
var img = MainImg;
MainImg = 加载图片(path);
if (MainImg) {
imageRect.set(new android.graphics.RectF(0, 0, MainImg.getWidth(), MainImg.getHeight()));
canvasMatrix.setRectToRect(imageRect, canvasRect, android.graphics.Matrix.ScaleToFit.CENTER);
};
if (img) {
img.recycle();
};
});
break;
};
});
});
ui.imageSave.click(function() {
if (MainImg) {
let x1 = imageRect.left < imageRect.right ? imageRect.left : imageRect.right,
y1 = imageRect.top < imageRect.bottom ? imageRect.top : imageRect.bottom,
x2 = imageRect.right >= imageRect.left ? imageRect.right : imageRect.left,
y2 = imageRect.bottom >= imageRect.top ? imageRect.bottom : imageRect.top;
let img = images.clip(MainImg, x1, y1, x2 - x1, y2 - y1);
let file = new java.io.File(imagePath);
var toPath = files.join(file.getParent(), files.getNameWithoutExtension(imagePath) + "(剪切)" + getTimeString() + "." + files.getExtension(imagePath));
//var toPath = "/sdcard/脚本/" + (new Date().getTime()) + ".png";
images.save(img, toPath, "png", 100);
//img.recycle();
media.scanFile(toPath);
threads.start(function() {
showImage(img, true);
});
toastLog("保存");
} else {
toastLog("没图");
};
});
//黑色画笔。
var paint = new Paint;
var paint1 = new Paint;
var paint2 = new Paint;
//paint1.setTextSize(75);
//paint.setTextAlign(Paint.Align.CENTER);
paint.setStrokeWidth(0.675);
paint1.setStrokeWidth(0.675);
paint.setStyle(Paint.Style.STROKE);
paint1.setStyle(Paint.Style.STROKE);
paint2.setStyle(Paint.Style.FILL);
//paint.setARGB(255, 0, 0, 0);
paint.setColor(colors.RED);
paint1.setColor(colors.GREEN);
paint2.setColor(colors.GREEN);
//paint.setTextSize(75);
//android.view.MotionEvent
var imageRect = new android.graphics.RectF;
var canvasRect = new android.graphics.RectF;
var canvasMatrix = new android.graphics.Matrix;
var ASX = new XYToMatrix(canvasMatrix);
//可以用两只手指移动缩放图像。
var touchControlPoint;
ui.canvas.setOnTouchListener(new android.view.View.OnTouchListener(function(view, event) {
try {
let W = view.getWidth();
let H = view.getHeight();
let PC = event.getPointerCount();
switch (event.getActionMasked()) {
case event.ACTION_MOVE:
try {
if (touchControlPoint) {
for (let i = 0; i < PC; i++) {
let id = event.getPointerId(i);
let x = event.getX(i);
let y = event.getY(i);
let XYary = ASX.matrixPoints(ASX.invertMatrix, [x, y]);
setRectXY(imageRect, touchControlPoint, XYary[0], XYary[1]);
};
};
} catch (e) {
throw "MOVE " + e;
};
break;
case event.ACTION_CANCEL:
toast("触摸被系统拦截\n可能是三指截屏等功能");
break;
case event.ACTION_OUTSIDE:
log("OUTSIDE");
break;
default:
let I = event.getActionIndex();
let ID = event.getPointerId(I);
let X = event.getX(I);
let Y = event.getY(I);
switch (event.getActionMasked()) {
case event.ACTION_DOWN:
try {
//log("down");
//当有新的手指按下时使坐标差为零。
let scale = ASX.getScaling();
let touchRadius = 50 / scale;
let XYary = ASX.matrixPoints(ASX.invertMatrix, [X, Y]);
let resAry = isRectXY(imageRect, XYary[0], XYary[1], touchRadius);
//log(resAry);
if (resAry) {
touchControlPoint = resAry;
};
} catch (e) {
throw "DOWN " + e;
};
break;
case event.ACTION_UP:
//最后一个手指抬起。
//log("up");
touchControlPoint = undefined;
break;
case event.ACTION_POINTER_DOWN:
break;
case event.ACTION_POINTER_UP:
break;
};
};
} catch (e) {
throw "imgTouch: " + e;
};
if (touchControlPoint) {
return true;
};
return ASX.touchListener(view, event);
}));
function setRectXY(rect, idAry, x, y) {
x = sinon(Math.floor(x - idAry[1]), 0, MainImg.getWidth());
y = sinon(Math.floor(y - idAry[2]), 0, MainImg.getHeight());
//log(x,y);
switch (idAry[0]) {
case 0:
if (rect.right != x && rect.bottom != y) {
rect.left = x;
rect.top = y;
};
break;
case 1:
if (rect.left != x && rect.bottom != y) {
rect.right = x;
rect.top = y;
};
break;
case 2:
if (rect.right != x && rect.top != y) {
rect.left = x;
rect.bottom = y;
};
break;
case 3:
if (rect.left != x && rect.top != y) {
rect.right = x;
rect.bottom = y;
};
break;
};
};
function sinon(a, b, c) {
return (a >= b && a < c) ? a : (a >= b ? c : b);
};
function isRectXY(rect, x, y, r) {
let x1 = x - rect.left,
y1 = y - rect.top,
x2 = x - rect.right,
y2 = y - rect.
没有合适的资源?快使用搜索试试~ 我知道了~
AutoJs源码-图片剪切↑
共1个文件
js:1个
需积分: 1 0 下载量 136 浏览量
2022-11-15
12:44:15
上传
评论
收藏 6KB 7Z 举报
温馨提示
AutoJs源码-图片剪切↑。本资源购买前提醒:本源码都是实际autojs项目模板,安装好autojs直接运行即可打开。1、支持低版本autojs。2、资源仅供学习与参考,请勿用于商业用途,否则产生的一切后果将由您自己承担!。3、安装过程详见具体资源,不会使用autojs谨慎下载
资源推荐
资源详情
资源评论
收起资源包目录
AutoJs源码-图片剪切↑.7z (1个子文件)
AutoJs源码-图片剪切↑.js 28KB
共 1 条
- 1
资源评论
[虚幻私塾】
- 粉丝: 335
- 资源: 1559
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功