java - 使用处理检测 Android 上的捏合 Action

标签 java android processing zooming pinchzoom

我正在开发一个用Processing 3编写的Android应用程序。它需要能够在启动捏合 Action “放大”时增加变量,并在“缩小”时减少变量。

在处理中是否有内置的方法来执行此操作,如果没有,有人可以给我一个关于创建自己的解决方案的正确方向的提示吗?

提前致谢。

最佳答案

看看Ketai Library - KetaiGesture :

Provides gesture recognition services to a processing sketch. To receive gesture events a sketch can define the following methods:

...

onPinch(float x, float y, float r) - x,y of center, r is the distance

使用捏合 Action 更改圆圈大小的代码示例:

import ketai.ui.*;
import android.view.MotionEvent;
 
float ellipseWidth = 50;
float ellipseHeight = 50;
KetaiGesture gesture;
 
void setup() {
  size(displayWidth, displayHeight);
  gesture = new KetaiGesture(this);
}
 
void draw() {
  orientation(PORTRAIT);
  background(0);
  fill(0);
  stroke(255);
  ellipse(width/2, height/2, ellipseWidth, ellipseHeight);
}
 
void onPinch (float x, float y, float d) {
  ellipseWidth += d;
  ellipseHeight += d;
}

public boolean surfaceTouchEvent(MotionEvent event) {
  //Call this to keep mouseX and mouseY updated
  super.surfaceTouchEvent(event);
 
  //Forward the event to the class for processing
  return gesture.surfaceTouchEvent(event);
}

希望这有帮助!

enter image description here

关于java - 使用处理检测 Android 上的捏合 Action ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56306643/

相关文章:

java - Jenkins Git 客户端插件无法执行 FetchCommand

java - 基于 Jersey 的 RESTful 服务报告进度

android - 带有 url 和文本的 AlertDialog

java - 将 json 对象添加到 Java HttpGet 请求到 C# WebApi

audio - 如何将音频录制到 WAV 文件?

java - 制作 Java map 制作工具的最佳方式?

java - Spring MVC 主页

android - 为 Objective-c 和 java 函数创建一个 dll

java - 向 ArrayList 添加元素时出现 NullPointerException

java - 使用 Swing 组件调整处理 Canvas 大小时闪烁