[問題] ScreenShot但得到全黑畫面

作者: comie   2017-04-28 14:12:04
環境如下
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 要另外處理
目前還沒試出來
煩請各位高手幫幫忙
感謝各位
作者: ssccg (23)   2017-04-28 16:47:00
拍照要用camera的takePicture,不是從view抓圖
作者: comie   2017-04-28 17:19:00
感謝您的指引 我再試看看

Links booklink

Contact Us: admin [ a t ] ucptt.com