2016-08-12 3 views
1

내 응용 프로그램에는 가운데에서 자른 구멍이있는 흰색 배경이 포함 된 사각형 ImageView가 있습니다. 그 뒤에 카메라 프리뷰를 설정 했으므로 구멍 만 카메라를 보여줍니다. 어떻게하면 여전히 얼굴을 볼 수 있도록 IMAGEVIEW.X AND Y AND HEIGHT AND WIDTH 사진을 찍을 수 있습니까? 기본적으로 스크린 샷을 이미지 뷰의 크기로 잘라냅니다.
enter image description here화면의 특정 부분을 프로그래밍 방식으로 화면에 표시합니다.

답변

0

희망이 도움이됩니다.

private void takeScreenshot() { 
Date now = new Date(); 
android.text.format.DateFormat.format("yyyy-MM-dd_hh:mm:ss", now); 

try { 
    // image naming and path to include sd card appending name you choose for file 
    String mPath = Environment.getExternalStorageDirectory().toString() + "/" + now + ".jpg"; 

    // create bitmap screen capture 
    View v1 = getWindow().getDecorView().getRootView(); 
    v1.setDrawingCacheEnabled(true); 
    Bitmap bitmap = Bitmap.createBitmap(v1.getDrawingCache()); 
    v1.setDrawingCacheEnabled(false); 

    File imageFile = new File(mPath); 

    FileOutputStream outputStream = new FileOutputStream(imageFile); 
    int quality = 100; 
    bitmap.compress(Bitmap.CompressFormat.JPEG, quality, outputStream); 
    outputStream.flush(); 
    outputStream.close(); 

    openScreenshot(imageFile); 
} catch (Throwable e) { 
    // Several error may come out with file handling or OOM 
    e.printStackTrace(); 
} 
} 
관련 문제