最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android 裁剪人臉類的實(shí)例代碼

 更新時(shí)間:2018年08月02日 16:56:06   作者:xi陽  
這篇文章主要介紹了Android 裁剪人臉類的實(shí)例代碼,需要的朋友可以參考下

人臉裁剪類

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<String> 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; // 構(gòu)造位圖生成的參數(shù),必須為565。類名+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]; // 分配人臉數(shù)組空間
    myFaceDetect = new FaceDetector(bitmap.getWidth(), bitmap.getHeight(), 5);
    int numberOfFaceDetected = myFaceDetect.findFaces(bitmap, myFace);
    if (numberOfFaceDetected <= 0) {// FaceDetector構(gòu)造實(shí)例并解析人臉
      bitmap.recycle();
      return null;
    }
    facePaths = new ArrayList<String>();
    for (int i = 0; i < numberOfFaceDetected; i++) {
      face = myFace[i];
      myMidPoint = new PointF();
      face.getMidPoint(myMidPoint);
      myEyesDistance = face.eyesDistance();  //得到人臉中心點(diǎn)和眼間距離參數(shù),并對每個(gè)人臉進(jìn)行畫框
      wuchax = myEyesDistance / 2 + myEyesDistance;
      wuchay = myEyesDistance * 2 / 3 + myEyesDistance;
      if (myMidPoint.x - wuchax < 0) {//判斷左邊是否出界
        tx = 0;
      } else {
        tx = (int) (myMidPoint.x - wuchax);
      }
      if (myMidPoint.x + wuchax > width) {//判斷右邊是否出界
        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) {//判斷下邊是否出界
        by = height;
      } else {
        by = (int) (myMidPoint.y + wuchay);
      }
      try {
        return Bitmap.createBitmap(bitmap, tx, ty, bx - tx, by - ty);//這里可以自行調(diào)整裁剪寬高
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
    bitmap.recycle();
    return bitmap;
  }
}

總結(jié)

以上所述是小編給大家介紹的Android 裁剪人臉的實(shí)例代碼,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時(shí)回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!

相關(guān)文章

  • Android APP編寫簡單答題器

    Android APP編寫簡單答題器

    這篇文章主要為大家詳細(xì)介紹了Android APP編寫簡單答題器,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-01-01
  • DownloadManager實(shí)現(xiàn)文件下載功能

    DownloadManager實(shí)現(xiàn)文件下載功能

    這篇文章主要為大家詳細(xì)介紹了DownloadManager實(shí)現(xiàn)文件下載功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-11-11
  • Android高手進(jìn)階教程(二十二)之Android中幾種圖像特效處理的集錦匯總!!

    Android高手進(jìn)階教程(二十二)之Android中幾種圖像特效處理的集錦匯總!!

    本篇文章主要介紹了Android中幾種圖像特效處理,比如圓角,倒影,還有就是圖片縮放,Drawable轉(zhuǎn)化為Bitmap,Bitmap轉(zhuǎn)化為Drawable等,有需要的可以了解一下。
    2016-11-11
  • Android編程獲取網(wǎng)絡(luò)時(shí)間實(shí)例分析

    Android編程獲取網(wǎng)絡(luò)時(shí)間實(shí)例分析

    這篇文章主要介紹了Android編程獲取網(wǎng)絡(luò)時(shí)間,結(jié)合實(shí)例形式對比分析了Android通過訪問網(wǎng)絡(luò)及通過GPS獲取網(wǎng)絡(luò)時(shí)間的具體步驟與實(shí)現(xiàn)技巧,需要的朋友可以參考下
    2016-01-01
  • ViewPager+RadioGroup仿微信主界面

    ViewPager+RadioGroup仿微信主界面

    這篇文章主要為大家詳細(xì)介紹了ViewPager+RadioGroup仿微信主界面,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-12-12
  • Android網(wǎng)格布局GridView實(shí)現(xiàn)漂亮的多選效果

    Android網(wǎng)格布局GridView實(shí)現(xiàn)漂亮的多選效果

    這篇文章主要為大家詳細(xì)介紹了Android網(wǎng)格布局GridView實(shí)現(xiàn)漂亮的多選效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-12-12
  • Android登錄記住多個(gè)密碼的實(shí)現(xiàn)方法

    Android登錄記住多個(gè)密碼的實(shí)現(xiàn)方法

    通過在popouWindow里面加上ListView,數(shù)據(jù)是把List以字符串按照J(rèn)SON的樣式存入本地,下面通過實(shí)例代碼給大家介紹android登錄記住多個(gè)密碼的實(shí)現(xiàn)方法,需要的的朋友參考下吧
    2017-07-07
  • Android調(diào)試神器stetho使用詳解和改造

    Android調(diào)試神器stetho使用詳解和改造

    今天小編就為大家分享一篇關(guān)于Android調(diào)試神器stetho使用詳解和改造,小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來看看吧
    2019-02-02
  • Android端使用Modbus協(xié)議的簡單方法

    Android端使用Modbus協(xié)議的簡單方法

    Modbus協(xié)議是全球第一個(gè)用于工業(yè)現(xiàn)場的總線協(xié)議,與外設(shè)交互可以采用串口通信,tcp等方式,這篇文章主要給大家介紹了關(guān)于Android端使用Modbus協(xié)議的簡單方法,需要的朋友可以參考下
    2021-11-11
  • Android選項(xiàng)菜單用法實(shí)例分析

    Android選項(xiàng)菜單用法實(shí)例分析

    這篇文章主要介紹了Android選項(xiàng)菜單用法,以完整實(shí)例形式較為詳細(xì)分析了Android選項(xiàng)菜單的布局及功能實(shí)現(xiàn)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下
    2015-09-09

最新評論

济源市| 深泽县| 定远县| 富宁县| 修文县| 赣榆县| 青州市| 临夏市| 剑河县| 大冶市| 昔阳县| 察隅县| 海兴县| 宜阳县| 黑山县| 阳江市| 伊春市| 南丰县| 黑水县| 两当县| 呼伦贝尔市| 延川县| 恩施市| 灵武市| 清徐县| 四子王旗| 富顺县| 玉门市| 赤峰市| 灵川县| 秦安县| 密山市| 沽源县| 尚义县| 图木舒克市| 广丰县| 嘉定区| 白城市| 南昌县| 如东县| 赤城县|