-1

Ich lade die Kamera in ein framelayout und ich möchte einen Screenshot machen. der Kameravorschau.Wie man den Screenshot der benutzerdefinierten Kamera in Android macht?

einen Screenshot zu nehmen:

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); 
} 

den Screenshot zu speichern:

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); 
    } 
} 

, wenn das Bild alles ist enter image description here

im Screenshot mit Ausnahme der Kamera Vorschau der Kamera gespeichert wird Lasten innerhalb eines Rahmenlayouts:

<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> 

Was mache ich bitte falsch? Vielen Dank im Voraus :)

+0

Haben Sie [diese] (http://stackoverflow.com/questions/13565221/taking-screenshot-camera-viewlayout-view-android-augmented-reality) überprüft? – solosodium

Antwort

3

einfach Ihre Ansicht als Argument in der folgenden Methode übergeben

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; 
} 

Und speichern Sie diese Bitmap nach Ihren Bedürfnissen.