How to implement a clipping human face class in Android
This article mainly introduces the relevant knowledge of "how to achieve a human face clipping class in Android". The editor shows you the operation process through an actual case. The operation method is simple, fast and practical. I hope this "how to achieve a human face clipping class in Android" article can help you solve the problem.
Face clipping class
Public final class FaceCj {private static BitmapFactory.Options BitmapFactoryOptionsbfo; private static ByteArrayOutputStream out; private static byte [] data; private static FaceDetector.Face [] myFace; private static FaceDetector myFaceDetect; private static int tx = 0; private static int ty = 0; private static int bx = 0; private static int by = 0; private static int width = 0; private static int height = 0; private static float wuchax = 0; private static float wuchay = 0; private static FaceDetector.Face face; private static PointF myMidPoint; private static float myEyesDistance Private static List facePaths; private static String facePath; public static Bitmap cutFace (Bitmap bitmap, Context context) {facePaths = null; BitmapFactoryOptionsbfo = new BitmapFactory.Options (); BitmapFactoryOptionsbfo.inPreferredConfig = Bitmap.Config.RGB_565; / / the parameter generated by the construction bitmap, must be 565. Class name + enum out = new ByteArrayOutputStream (); bitmap.compress (Bitmap.CompressFormat.JPEG, 50, out); data = out.toByteArray (); bitmap = BitmapFactory.decodeByteArray (data, 0, data.length, BitmapFactoryOptionsbfo); try {out.flush (); out.close ();} catch (IOException e) {/ / TODO Auto-generated catch block e.printStackTrace ();} width = bitmap.getWidth () Height = bitmap.getHeight (); myFace = new FaceDetector.Face [5]; / / assign face array space myFaceDetect = new FaceDetector (bitmap.getWidth (), bitmap.getHeight (), 5); int numberOfFaceDetected = myFaceDetect.findFaces (bitmap, myFace); if (numberOfFaceDetected width) {/ / determine whether the right side is out of bounds bx = width;} else {bx = (int) (myMidPoint.x + wuchax) } if (myMidPoint.y-wuchay
< 0) {//判断上边是否出界 ty = 0; } else { ty = (int) (myMidPoint.y - wuchay); } if (myMidPoint.y + wuchay >Height) {/ / determine whether the following edges are out of bounds by = height;} else {by = (int) (myMidPoint.y + wuchay);} try {return Bitmap.createBitmap (bitmap, tx, ty, bx-tx, by-ty); / / you can adjust the cutting width and height} catch (Exception e) {e.printStackTrace ();}} bitmap.recycle () Return bitmap;}} on "how to implement a cropped human face class in Android", thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.