环境如下
IDE: Android Studio 2.3
手机: Note5, android 6.0.1
尝试利用内建的 com.google.android.gms.vision.face.FaceDetector 抓人脸
当抓到人脸时会把人脸框起来
加入touchevent
利用touchDown来做 screenshot
但存到手机的bmp档,背景全部是黑色的,只剩下框框而已
程式片段如下
public void SnapshotFace()
{
Bitmap bitmap = takeScreenshot();
saveBitmap(bitmap);
}
public Bitmap takeScreenshot()
{
View rootView = getWindow().getDecorView().getRootView();
rootView.setDrawingCacheEnabled(true);
return rootView.getDrawingCache();
}
public void saveBitmap(Bitmap bitmap) {
Calendar c = Calendar.getInstance();
System.out.println("Current time => "+c.getTime());
SimpleDateFormat df = new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss");
String formattedDate = df.format(c.getTime());
String str= "Screen_"+ formattedDate +".pgng";
File imagePath = new File(Environment.getExternalStorageDirectory() +
"/"+ str);
FileOutputStream fos;
try {
fos = new FileOutputStream(imagePath);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos);
fos.flush();
fos.close();
} catch (FileNotFoundException e) {
Log.e("GREC", e.getMessage(), e);
} catch (IOException e) {
Log.e("GREC", e.getMessage(), e);
}
}
找了stackoverflow
有人说是 camera 的 view 要另外处理
目前还没试出来
烦请各位高手帮帮忙
感谢各位