• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps drawing web view off-screen

Hi All,

I bit new to android development but so far very impressed.

I have a slight problem with trying to render the web view off-screen so that the user can't see it and then generate a bitmap of that. I was wondering how do you go about rendering the web view so that it cannot be seen, should be OK with the bitmap part.

Many Thanks if you can help,
 
Ah cool thanks it worked.

Thought the bitmap bit would be ok but I ended up with a black screen of the screenshot but at the correct size I told it too. The page does exist too.

Here is the code I am using:

Code:
WebView webview = new WebView(null);
webview.loadUrl("file:///android_asset/www/pages/page2.html");
				
Bitmap bm = Bitmap.createBitmap(800, 600, Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(bm);
webview.draw(c);
OutputStream stream = null;
try {
       stream = new FileOutputStream(Environment.getExternalStorageDirectory() +"/thePage.jpg");
	bm.compress(CompressFormat.JPEG, 80, stream);
	if (stream != null) stream.close();
		return new PluginResult(PluginResult.Status.OK); 
} catch (IOException e) {
	return new PluginResult(PluginResult.Status.ERROR, e.toString());
} finally {
	bm.recycle();
}

Thanks if anyone can help.
 
Bump

Anyone know of any solutions to this rendering off-screen, I have tried the onPageFinished() method but is does not seem to fire.

Thanks,
 
Back
Top Bottom