我的应用程序要求用户可以在屏幕上书写签名。签名应该能够被提取到图像中。
我应该怎么做?
是否有现有的android进程/观察者?或者它们是否可能允许该功能的库/插件?
答案 0 :(得分:0)
在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"/>