Android保存和识别手势
2016-09-11 13:59
316 查看
通过手势编辑组件android.gesture.GestureOverlayView来编辑手势,使用代码如下:
<android.gesture.GestureOverlayView
android:id="@+id/gesture"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gestureStrokeType="multiple"/>为组件绑定事件监听器:
<span style="white-space:pre"> </span>gestureView.addOnGesturePerformedListener(new GestureOverlayView.OnGesturePerformedListener(){
<span style="white-space:pre"> </span>public void onGesturePerformed(GestureOverlayView overlay,final Gesture gesture){}
<span style="white-space:pre"> </span>}
设置手势编辑时的一些属性:
<span style="white-space:pre"> </span>gestureView.setGestureColor(Color.RED);
gestureView.setGestureStrokeWidth(4);
保存手势:
//gesture.Bitmap(int width,int height,int inset,int color);
<span style="white-space:pre"> </span>Bitmap bitmap = gesture.toBitmap(128,128,10,0xffff0000);加载手势库:
// 加载手势库
gestureLib = GestureLibraries.fromFile("/mnt/sdcard/mygestures");
// 判断手势加载是否成功
if(gestureLib.load()){
Toast.makeText(RecognizeGesture.this, "读取手势库成功", Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(RecognizeGesture.this, "读取手势库失败", Toast.LENGTH_SHORT).show();
}识别手势:
ArrayList<Prediction> predictions = gestureLib.recognize(gesture);
ArrayList<String> result = new ArrayList<String>();
for(Prediction pred:predictions){
if(pred.score > 2){
result.add("与手势"+pred.name+"相似度为:"+pred.score);
}
}
<android.gesture.GestureOverlayView
android:id="@+id/gesture"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gestureStrokeType="multiple"/>为组件绑定事件监听器:
<span style="white-space:pre"> </span>gestureView.addOnGesturePerformedListener(new GestureOverlayView.OnGesturePerformedListener(){
<span style="white-space:pre"> </span>public void onGesturePerformed(GestureOverlayView overlay,final Gesture gesture){}
<span style="white-space:pre"> </span>}
设置手势编辑时的一些属性:
<span style="white-space:pre"> </span>gestureView.setGestureColor(Color.RED);
gestureView.setGestureStrokeWidth(4);
保存手势:
GestureLibrary gestureLib = GestureLibraries.fromFile("/mnt/sdcard/mygestures"); // 手势库添加手 gestureLib.addGesture(gestureName.getText().toString(),gesture); gestureLib.save();将手势转为Bitmap :
//gesture.Bitmap(int width,int height,int inset,int color);
<span style="white-space:pre"> </span>Bitmap bitmap = gesture.toBitmap(128,128,10,0xffff0000);加载手势库:
// 加载手势库
gestureLib = GestureLibraries.fromFile("/mnt/sdcard/mygestures");
// 判断手势加载是否成功
if(gestureLib.load()){
Toast.makeText(RecognizeGesture.this, "读取手势库成功", Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(RecognizeGesture.this, "读取手势库失败", Toast.LENGTH_SHORT).show();
}识别手势:
ArrayList<Prediction> predictions = gestureLib.recognize(gesture);
ArrayList<String> result = new ArrayList<String>();
for(Prediction pred:predictions){
if(pred.score > 2){
result.add("与手势"+pred.name+"相似度为:"+pred.score);
}
}
相关文章推荐
- Android手势识别ViewFlipper触摸动画
- 简述Android触摸屏手势识别
- 简述Android触摸屏手势识别
- 简述Android触摸屏手势识别
- 简述Android触摸屏手势识别
- 简述Android触摸屏手势识别(转)
- 编写 Android 触摸屏手势识别程序
- android的手势识别例子
- 简述Android触摸屏手势识别
- 手势识别兼容Android 1.x和2.x的代码
- Android日历功能有GestureDetector手势识别功能
- 【Android游戏开发十六】Android Gesture之【触摸屏手势识别】操作!
- Android游戏开发之旅 View中手势识别
- 简述Android触摸屏手势识别
- Android游戏开发之旅(十一)View中手势识别
- 【Android游戏开发十六】Android Gesture之【触摸屏手势识别】操作!利用触摸屏手势实现一个简单切换图片的功能!
- 编写 Android 触摸屏手势识别程序
- Android+手势识别详解
- 简述Android触摸屏手势识别
- android 手势识别例子