Created
June 19, 2012 16:21
-
-
Save johnkil/2955070 to your computer and use it in GitHub Desktop.
ScreenShot Android Util
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.app.Activity; | |
import android.graphics.Bitmap; | |
import android.graphics.Bitmap.Config; | |
import android.graphics.Canvas; | |
import android.view.View; | |
public class ScreenShot { | |
private final View view; | |
/** Create snapshots based on the view and its children. */ | |
public ScreenShot(View root) { | |
this.view = root; | |
} | |
/** Create snapshot handler that captures the root of the whole activity. */ | |
public ScreenShot(Activity activity) { | |
final View contentView = activity.findViewById(android.R.id.content); | |
this.view = contentView.getRootView(); | |
} | |
/** Create snapshot handler that captures the view with target id of the activity. */ | |
public ScreenShot(Activity activity, int id) { | |
this.view = activity.findViewById(id); | |
} | |
/** Take a snapshot of the view. */ | |
public Bitmap snap() { | |
Bitmap bitmap = Bitmap.createBitmap(this.view.getWidth(), | |
this.view.getHeight(), Config.ARGB_8888); | |
Canvas canvas = new Canvas(bitmap); | |
view.draw(canvas); | |
return bitmap; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment