【发布时间】:2015-08-12 04:37:20
【问题描述】:
我的应用程序要求用户可以在屏幕上写下他们的签名。签名应该能够被提取到图像中。
我该怎么办?
是否有一个现有的 android 进程/观察者用于此?或者它们是任何可能允许该功能的库/插件?
【问题讨论】:
-
谢谢,看看。
标签: android capture touchscreen
我的应用程序要求用户可以在屏幕上写下他们的签名。签名应该能够被提取到图像中。
我该怎么办?
是否有一个现有的 android 进程/观察者用于此?或者它们是任何可能允许该功能的库/插件?
【问题讨论】:
标签: android capture touchscreen
在 Activity 中使用此代码:
try {
GestureOverlayView gestureView = (GestureOverlayView) findViewById(R.id.signaturePad);
gestureView.setDrawingCacheEnabled(true);
Bitmap bm = Bitmap.createBitmap(gestureView.getDrawingCache());
File f = new File(Environment.getExternalStorageDirectory()+ File.separator + "signature.png");
f.createNewFile();
FileOutputStream os = new FileOutputStream(f);
os = new FileOutputStream(f);
//compress to specified format (PNG), quality - which is ignored for PNG, and out stream
bm.compress(Bitmap.CompressFormat.PNG, 100, os);
os.close();
} catch (Exception e) {
Log.v("Gestures", e.getMessage());
e.printStackTrace();
}
}
在xml中:
<android.gesture.GestureOverlayView
android:id="@+id/signaturePad"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="5"
android:background="@android:color/white"
android:eventsInterceptionEnabled="true"
android:fadeEnabled="false"
android:gestureColor="@android:color/black"
android:gestureStrokeLengthThreshold="0.1"
android:gestureStrokeType="multiple"
android:orientation="vertical"/>
【讨论】: