1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
| public class ScreenShot {
private Bitmap bitmap;
private String url;
public void GetScreenShot(Context context){
WebView webView = new WebView(context);
webView.setPictureListener(new PictureListener(){
@Override
public void onNewPicture(WebView view, Picture picture) {
if(picture.getWidth()>0 && picture.getHeight()>0){
bitmap = Bitmap.createBitmap( picture.getWidth(), picture.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas( bitmap );
picture.draw( canvas );
//sauvegarde du bitmap sur la sdcard
FileOutputStream fos = null;
try {
fos = new FileOutputStream(
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES)+
"/"+System.currentTimeMillis()+".jpg" );
BufferedOutputStream bos = new BufferedOutputStream(fos);
if ( fos != null )
{
bitmap.compress(Bitmap.CompressFormat.JPEG, 90, bos );
bos.flush();
bos.close();
fos.close();
}
} catch( Exception e )
{
//...
}
}
}
});
webView.loadUrl(url);
}
public Bitmap GetBitmap(){
return bitmap;
}
public String GetUrl(){
return url;
}
public void SetUrl(String nUrl){
url = nUrl;
}
} |