본문 바로가기

Picture를 이용한 스크린샷 캡쳐 구현하기

by 머니해커_개발자 2017. 6. 21.

public void onSavePageAllScreenShot() {

        handler.sendMsgQuick(6);

        wv.setDrawingCacheEnabled(true);

        Picture picture = wv.capturePicture();

        int captureHeight = DEVICE_HEIGHT -255;

        Bitmap saveAllScreenShot = Bitmap.createBitmap(picture.getWidth(), captureHeight, Bitmap.Config.ARGB_8888);

        Canvas c = new Canvas( saveAllScreenShot );

        picture.draw( c );

        SimpleDateFormat formatter = new java.text.SimpleDateFormat("yyyyMMdd_hhmmss");

        Date today = new Date();

        String strDate = formatter.format(today);

        String dirPath = Environment.getExternalStorageDirectory().toString() + SAVE_FOLDER;

        File file = new File(dirPath);

        if( !file.exists() )  // 원하는 경로에 폴더가 있는지 확인

            file.mkdirs();

        File hFile = new File( "" + dirPath + "/SC_" + strDate +".jpg" );

        FileOutputStream fos;

        try {

            fos = new FileOutputStream(hFile);

            saveAllScreenShot.compress(Bitmap.CompressFormat.JPEG, 100, fos);

            fos.close();

        } catch ( Exception e){

            Log.i("error", e.getMessage());

        }


        wv.setDrawingCacheEnabled(false);

        handler.sendMsgQuick(7);

    }


}

댓글

최신글 전체

이미지
제목
글쓴이
등록일