-1

나는 framelayout에 카메라를로드하고 나는 스크린 샷을 찍고 싶다. 카메라 미리보기의 이미지가 모든 것을 저장 카메라 미리보기 enter image description hereandroid에서 맞춤 카메라 스크린 샷을 찍는 방법?

카메라를 제외하고 스크린 샷입니다

public void saveBitmap(Bitmap bitmap) { 
    File imagePath = new File(Environment.getExternalStorageDirectory() + "/screenshot.png"); 
    FileOutputStream fos; 
    try { 
     fos = new FileOutputStream(imagePath); 
     bitmap.compress(android.graphics.Bitmap.CompressFormat.PNG, 100, fos); 
     fos.flush(); 
     fos.close(); 
    } catch (FileNotFoundException e) { 
     Log.e("GREC", e.getMessage(), e); 
    } catch (IOException e) { 
     Log.e("GREC", e.getMessage(), e); 
    } 
} 

:

public void onClick(View v) { 
    View v1 = L1.getRootView(); 
    v1.setDrawingCacheEnabled(true); 
    Bitmap bm = v1.getDrawingCache(); 
    BitmapDrawable bitmapDrawable = new BitmapDrawable(bm); 
    image = (ImageView) findViewById(R.id.ImageView011); 
    image.setBackgroundDrawable(bitmapDrawable); 

    //Bitmap bitmap = takeScreenshot(); 
    saveBitmap(bm); 
} 

이 스크린 샷을 저장 :

은 스크린 샷을 촬영합니다 프레임 레이아웃 내부에로드 :

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
tools:context="mobapptut.com.camapp.bellowLollipop" 
android:baselineAligned="false" 
android:id="@+id/containerImg"> 


<FrameLayout 
android:id="@+id/camera_preview" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:layout_alignParentLeft="true" 
android:layout_alignParentStart="false"> 


</FrameLayout> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent"> 

<ImageView android:id="@+id/ImageView01" 
android:layout_height="wrap_content" 
android:layout_width="wrap_content" /> 

</LinearLayout> 
<ImageView 
android:layout_width="match_parent" 
android:layout_height="300dp" 
android:id="@+id/captured_image" 
android:layout_alignParentLeft="true" 
android:layout_alignParentStart="true" 
android:contentDescription="desc" /> 


<ImageButton 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:id="@+id/plusBtnImg" 
android:layout_gravity="left|bottom" 
android:src="@mipmap/zoom_in2" 
android:layout_alignParentBottom="true" 
android:layout_toEndOf="@+id/imageView2" 
android:background="#00ffffff" /> 


<ImageButton 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:id="@+id/minusBtnImg" 
android:layout_gravity="left|bottom" 
android:src="@mipmap/zoom_out2" 
android:layout_above="@+id/plusBtnImg" 
android:layout_toRightOf="@+id/imageView2" 
android:background="#00ffffff" /> 

<Button 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:text="Go Back!" 
android:id="@+id/backButton" 
android:layout_alignParentBottom="true" 
android:layout_centerHorizontal="true" 
android:layout_gravity="right|bottom" 
android:layout_alignParentRight="true" /> 

<Button 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:text="Save Picture" 
android:id="@+id/button12" 
android:layout_alignParentBottom="true" 
android:layout_centerHorizontal="true"/> 

<Button 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:text="Take Screenshot" 
android:id="@+id/Button01" 
/> 

<ImageView 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:text="Take Screenshot" 
android:id="@+id/ImageView011" 
/> 
</RelativeLayout> 

내가 뭘 잘못하고 있니? 감사합니다 사전에 :)

+0

[this] (http://stackoverflow.com/questions/13565221/taking-screenshot-camera-viewlayout-view-android-augmented-reality)를 확인 했습니까? – solosodium

답변

3

그냥 아래의 방법

public Bitmap takeScreenShot(View view) { 
    view.setDrawingCacheEnabled(true); 
    view.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH); 
    view.buildDrawingCache(); 
    if (view.getDrawingCache() == null) 
     return null; 
    Bitmap snapshot = Bitmap.createBitmap(view.getDrawingCache()); 
    view.setDrawingCacheEnabled(false); 
    view.destroyDrawingCache(); 
    return snapshot; 
} 

의 인수로 원하는보기를 전달하고 사용자의 요구에 따라이 비트 맵을 저장합니다.

관련 문제