Study/Android

같은 스크린샷만 찍힐때

Answer Choi 2015. 2. 12. 08:31
반응형



스크린샷을 찍는데, 확인을 못했던건지 괜찮았던건지 처음찍었던 화면만 나오는 경우가 있군요. 

 

Activity의 전환이 없으면 처음 찍었던 스크린샷만 나옵니다.ㅠ


이럴 경우 destroyDrawingCache();를 해주시면 이런 증상이 없어집니다.


  1. share.buildDrawingCache();
  2. Bitmap bm=share.getDrawingCache();
  3. String filename="/"+System.currentTimeMillis()+".jpg";
  4. String sharefile=Environment.getExternalStorageDirectory().toString()+filename;
  5. try{
  6.     out=new FileOutputStream(sharefile);
  7.     bm.compress(Bitmap.CompressFormat.JPEG,100, out);
  8.     Intent shareIntent = new Intent();
  9.     shareIntent.setAction(Intent.ACTION_SEND);
  10.     shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(sharefile));
  11.     shareIntent.setType("image/jpeg");
  12.     startActivity(Intent.createChooser(shareIntent, getResources().getText(R.string.share)));
  13. }catch(Exception e){
  14.     e.printStackTrace();
  15. }
  16. share.destroyDrawingCache();

 

1번 라인을 보시면 share가 스크린샷을 찍으려는 뷰내지는 레이아웃입니다.

 

이부분을 buildDrawingCache();를 이용하여 캐시에 저장해주고, 2번 라인에서처럼 


getDrawingCache();를 사용하여 비트맵으로 가져옵니다.

 

3~8번은 jpg파일로 저장하는 부분이고, 10~16까지하면 공유를 하는 부분입니다.

 

17번에 보시면 1번라인에서 캐쉬로 그렸던 부분을 destroy해줍니다.

 

이렇게 하면 같은 activity안에서 찍을때마다 첫번째 화면만 찍히는 문제를 해결할 수 있습니다.^^

 

반응형