這篇文章主要介紹“Android中如何開(kāi)發(fā)一個(gè)證件照DIY小程序”,在日常操作中,相信很多人在Android中如何開(kāi)發(fā)一個(gè)證件照DIY小程序問(wèn)題上存在疑惑,小編查閱了各式資料,整理出簡(jiǎn)單好用的操作方法,希望對(duì)大家解答”Android中如何開(kāi)發(fā)一個(gè)證件照DIY小程序”的疑惑有所幫助!接下來(lái),請(qǐng)跟著小編一起來(lái)學(xué)習(xí)吧!
創(chuàng)新互聯(lián)專(zhuān)注為客戶提供全方位的互聯(lián)網(wǎng)綜合服務(wù),包含不限于成都網(wǎng)站建設(shè)、成都網(wǎng)站設(shè)計(jì)、奉化網(wǎng)絡(luò)推廣、小程序設(shè)計(jì)、奉化網(wǎng)絡(luò)營(yíng)銷(xiāo)、奉化企業(yè)策劃、奉化品牌公關(guān)、搜索引擎seo、人物專(zhuān)訪、企業(yè)宣傳片、企業(yè)代運(yùn)營(yíng)等,從售前售中售后,我們都將竭誠(chéng)為您服務(wù),您的肯定,是我們大的嘉獎(jiǎng);創(chuàng)新互聯(lián)為所有大學(xué)生創(chuàng)業(yè)者提供奉化建站搭建服務(wù),24小時(shí)服務(wù)熱線:028-86922220,官方網(wǎng)址:www.cdcxhl.com 打開(kāi)AndroidStudio項(xiàng)目級(jí)build.gradle文件。
??
增量添加如下maven地址:
buildscript { repositories { maven {url 'http://developer.huawei.com/repo/'} } }allprojects { repositories { maven { url 'http://developer.huawei.com/repo/'} }}
??把人臉識(shí)別的SDK和基礎(chǔ)SDK引入
dependencies{ // 引入基礎(chǔ)SDK implementation 'com.huawei.hms:ml-computer-vision:1.0.2.300' // 引入人臉檢測(cè)能力包 implementation 'com.huawei.hms:ml-computer-vision-image-segmentation-body-model:1.0.2.301' }
??要使應(yīng)用程序能夠在用戶從華為應(yīng)用市場(chǎng)安裝您的應(yīng)用程序后,自動(dòng)將最新的機(jī)器學(xué)習(xí)模型更新到用戶設(shè)備,請(qǐng)將以下語(yǔ)句添加到該應(yīng)用程序的AndroidManifest.xml文件中:
@Overrideprotected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); if (!allPermissionsGranted()) { getRuntimePermissions(); }}@Overridepublic void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { super.onRequestPermissionsResult(requestCode, permissions, grantResults); if (requestCode != PERMISSION_REQUESTS) { return; } boolean isNeedShowDiag = false; for (int i = 0; i < permissions.length; i++) { if (permissions[i].equals(Manifest.permission.READ_EXTERNAL_STORAGE) && grantResults[i] != PackageManager.PERMISSION_GRANTED) { // 如果相機(jī)或者存儲(chǔ)權(quán)限沒(méi)有授權(quán),則需要彈出授權(quán)提示框 isNeedShowDiag = true; } } if (isNeedShowDiag && !ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.CALL_PHONE)) { AlertDialog dialog = new AlertDialog.Builder(this) .setMessage(getString(R.string.camera_permission_rationale)) .setPositiveButton(getString(R.string.settings), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS); intent.setData(Uri.parse("package:" + getPackageName())); // 根據(jù)包名打開(kāi)對(duì)應(yīng)的設(shè)置界面 startActivityForResult(intent, 200); startActivity(intent); } }) .setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { finish(); } }).create(); dialog.show(); }}
??可以通過(guò)圖像分割檢測(cè)配置器“MLImageSegmentationSetting”創(chuàng)建圖像分割檢測(cè)器。
MLImageSegmentationSetting setting = new MLImageSegmentationSetting.Factory() .setAnalyzerType(MLImageSegmentationSetting.BODY_SEG) .setExact(true) .create(); this.analyzer = MLAnalyzerFactory.getInstance().getImageSegmentationAnalyzer(setting);
??可以通過(guò)圖像分割檢測(cè)配置器“MLImageSegmentationSetting”創(chuàng)建圖像分割檢測(cè)器。
MLFrame mlFrame = new MLFrame.Creator().setBitmap(this.originBitmap).create();
// 創(chuàng)建一個(gè)task,處理圖像分割檢測(cè)器返回的結(jié)果。 Tasktask = analyzer.asyncAnalyseFrame(frame); // 異步處理圖像分割檢測(cè)器返回結(jié)果 Task task = this.analyzer.asyncAnalyseFrame(mlFrame); task.addOnSuccessListener(new OnSuccessListener () { @Override public void onSuccess(MLImageSegmentation mlImageSegmentationResults) { // Transacting logic for segment success. if (mlImageSegmentationResults != null) { StillCutPhotoActivity.this.foreground = mlImageSegmentationResults.getForeground(); StillCutPhotoActivity.this.preview.setImageBitmap(StillCutPhotoActivity.this.foreground); StillCutPhotoActivity.this.processedImage = ((BitmapDrawable) ((ImageView) StillCutPhotoActivity.this.preview).getDrawable()).getBitmap(); StillCutPhotoActivity.this.changeBackground(); } else { StillCutPhotoActivity.this.displayFailure(); } } }).addOnFailureListener(new OnFailureListener() { @Override public void onFailure(Exception e) { // Transacting logic for segment failure. StillCutPhotoActivity.this.displayFailure(); return; } });
this.backgroundBitmap = BitmapUtils.loadFromPath(StillCutPhotoActivity.this, id, targetedSize.first, targetedSize.second);BitmapDrawable drawable = new BitmapDrawable(backgroundBitmap);this.preview.setDrawingCacheEnabled(true);this.preview.setBackground(drawable);this.preview.setImageBitmap(this.foreground);this.processedImage = Bitmap.createBitmap(this.preview.getDrawingCache());this.preview.setDrawingCacheEnabled(false);
到此,關(guān)于“Android中如何開(kāi)發(fā)一個(gè)證件照DIY小程序”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實(shí)踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識(shí),請(qǐng)繼續(xù)關(guān)注創(chuàng)新互聯(lián)-成都網(wǎng)站建設(shè)公司網(wǎng)站,小編會(huì)繼續(xù)努力為大家?guī)?lái)更多實(shí)用的文章!