2015-05-29 58 views
-2

我的应用程序有一个要求,用户可以在屏幕上书写他们的签名。签名应该能够被提取到图像中。在触摸屏上捕获文字

我应该怎么办?

是否有一个现有的Android进程/观察员为此?或者他们是否有可能允许功能的库/插件?

+0

使用手势... –

+0

谢谢,考虑看看。 –

回答

0

使用此代码在活动时间:

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"/> 
+0

谢谢,应该给它一个镜头。问:应用程序何时知道何时创建位图? –

+0

在视图上有签名后调用上面的代码。 –

+0

嗯。谢谢。给它一个镜头。 –