안드로이드 개발 질문/답변
(글 수 45,052)
인터넷을 하는 도중에 스크린 캡쳐를 하는 어플을 만들고 싶어서
혹시나 하는 마음에 브라우저 앞에 투명한 레이어를 띄우고 찍어 봤지만..
역시 안되더군요.. 어떻게 해야 브라우저 화면이나 다른 화면들을
스크린 캡쳐 할 수 있을까요? ㅠㅠ
소스는 http://www.androidpub.com/67943 참고했습니다.
2010.11.09 13:39:48
Bitmap bitmap = Bitmap.createBitmap(screenWidth, screenHeight, Bitmap.Config.ARGB_8888); // 원하는 가로, 세로 길이 Canvas canvas = new Canvas(bitmap); xxxView().draw(canvas); // 캡쳐 원하는 뷰에 draw에 canvas 넘겨주기 File file = new File(fileName); file.createNewFile(); // 파일 만들어서 저장 // 이후는 아실꺼라 믿음. FileOutputStream fos = new FileOutputStream(file); bitmap.compress(CompressFormat.PNG, 100, fos); fos.flush(); fos.close();




this.getRootView().setDrawingCacheEnabled(true); // 캡쳐 할 수 있도록 권한 설정하는 부분이고 // 화면 캡쳐해서 비트맵으로 가져오는 부분이구요. this.getRootView().buildDrawingCache(); Bitmap srcimg = this.getRootView().getDrawingCache(); try { FileOutputStream out = new FileOutputStream("/sdcard/captureScreen.png"); srcimg.compress(Bitmap.CompressFormat.PNG, 100, out); } catch (FileNotFoundException e) { Log.d("FileNotFoundException:", e.getMessage()); } // 비트맵 파일로 만드는 부분이구요.즐거운 하루 보내세요~