sitelink1 | http://riucc.tistory.com/264 |
---|---|
sitelink2 | |
sitelink3 |
public void picCapture(View v ){ // 버튼 onClick 리스너
// WRITE_EXTERNAL_STORAGE 외부 공간 사용 권한 허용
ActivityCompat.requestPermissions(this, new String[] {Manifest.permission.WRITE_EXTERNAL_STORAGE},1);
linearLayout1.buildDrawingCache(); // 캡처할 뷰를 지정하여 buildDrawingCache() 한다
Bitmap captureView = linearLayout1.getDrawingCache(); // 캡쳐할 뷰를 지정하여 getDrawingCache() 한다
FileOutputStream fos; // FileOutputStream 이용 파일 쓰기 한다
String strFolderPath = Environment.getExternalStorageDirectory().getAbsolutePath() + CAPTURE_PATH;
File folder = new File(strFolderPath);
if(!folder.exists()) { // 해당 폴더 없으면 만들어라
folder.mkdirs();
}
String strFilePath = strFolderPath + "/" + System.currentTimeMillis() + ".png";
File fileCacheItem = new File(strFilePath);
try {
fos = new FileOutputStream(fileCacheItem);
captureView.compress(Bitmap.CompressFormat.PNG, 100, fos);
} catch (FileNotFoundException e) {
e.printStackTrace();
} finally {
Toast.makeText(this, "영상을 캡쳐했습니다", Toast.LENGTH_SHORT).show();
}
}