In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-13 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces Android how to achieve on-screen handwritten signature, the article is very detailed, has a certain reference value, interested friends must read it!
The principle of Android screen handwriting signature is to use the mobile phone screen as a drawing board, the user's finger as a paintbrush, and the fingers to and fro on the screen, and the screen will show the trajectory of the fingers, just like a paintbrush writing on the drawing board. The realization of handwriting signature needs to be combined with the drawing path tool Path, and the moveTo method of Path object is called when there is a press action to move the path starting point to the touch point; when there is a move operation, the quadTo method of Path object is called to record the path between this touch point and the last touch point; when there is a move operation and lift action, the drawPath method of Canvas object is called to draw the touch on the canvas.
The layout code of the layout/activity_signature.xml interface is as follows:
The SignatureActivity.java logic code is as follows:
Package com.fukaimei.touchevent;import android.graphics.Bitmap;import android.os.Bundle;import android.os.Handler;import android.support.v7.app.AppCompatActivity;import android.view.View;import android.view.View.OnClickListener;import android.widget.ImageView;import android.widget.Toast;import com.fukaimei.touchevent.filedialog.dialog.FileSaveFragment;import com.fukaimei.touchevent.util.BitmapUtil;import com.fukaimei.touchevent.widget.SignatureView;public class SignatureActivity extends AppCompatActivity implements OnClickListener, FileSaveFragment.FileSaveCallbacks {private SignatureView view_signature; private ImageView iv_signature_new Private Bitmap mBitmap; @ Override protected void onCreate (Bundle savedInstanceState) {super.onCreate (savedInstanceState); setContentView (R.layout.activity_signature); view_signature = (SignatureView) findViewById (R.id.view_signature); iv_signature_new = (ImageView) findViewById (R.id.iv_signature_new); findViewById (R.id.btn_add_signature) .setOnClickListener (this); findViewById (R.id.btn_end_signature) .setOnClickListener (this) FindViewById (R.id.btn_reset_signature) .setOnClickListener (this); findViewById (R.id.btn_revoke_signature) .setOnClickListener (this); findViewById (R.id.btn_save_signature) .setOnClickListener (this) } @ Override public void onClick (View v) {if (v.getId () = = R.id.btn_save_signature) {if (mBitmap = = null) {Toast.makeText (this, "Please start and then end signature", Toast.LENGTH_LONG). Show (); return;} FileSaveFragment.show (this, "jpg");} else if (v.getId () = = R.id.btn_add_signature) {view_signature.setDrawingCacheEnabled (true) } else if (v.getId () = = R.id.btn_reset_signature) {view_signature.clear ();} else if (v.getId () = = R.id.btn_revoke_signature) {view_signature.revoke () } else if (v.getId () = = R.id.btn_end_signature) {if (view_signature.isDrawingCacheEnabled ()! = true) {Toast.makeText (this, "Please sign first", Toast.LENGTH_LONG). Show ();} else {mBitmap = view_signature.getDrawingCache (); iv_signature_new.setImageBitmap (mBitmap); mHandler.postDelayed (mResetCache, 100);}} private Handler mHandler = new Handler () Private Runnable mResetCache = new Runnable () {@ Override public void run () {view_signature.setDrawingCacheEnabled (false); view_signature.setDrawingCacheEnabled (true);}}; @ Override public boolean onCanSave (String absolutePath, String fileName) {return true;} @ Override public void onConfirmSave (String absolutePath, String fileName) {String path = String.format ("% s, absolutePath, fileName); BitmapUtil.saveBitmap (path, mBitmap," jpg ", 80) Toast.makeText (this, "successfully Save Picture File: + path, Toast.LENGTH_LONG). Show ();}} above is all the content of the article" how to achieve on-screen handwritten signature in Android ". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.