Hi,
The webview.createsnapshot() function does work as intended.The width of -1
or 0 indicates that the webview's parent view has not yet completed the
layout process for your WebView.
The best time to take the snapshot of the WebWiew would be when the webpage
withing the webview has finished loading.
You can find this point by setting a callback to be invoked when the web
page has finished loading. This can be done by setting
a WebChromeClient to receive notifications on page load progress, and
calling the snapshot function when the load progress is 100%.
The sample code below shows how to do this:
public class WebViewTest extends Activity {
/** Called when the activity is first created. */
private final static int W = 240;
private final static int H = 180;
WebView w;
ImageView imageview;
WebChromeCallback mWebChromeCallback;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
w = (WebView) findViewById(R.id.webview);
w.loadUrl("http://www.google.com");
mWebChromeCallback = new WebChromeCallback();
w.setWebChromeClient(mWebChromeCallback);
w.requestFocus();imageview = (ImageView)findViewById(R.id.imageview
);
}
private class WebChromeCallback extends WebChromeClient {
private int mLastProgress;
//
// Overridden WebChromeCallback functions
//
@Override
public void onProgressChanged(WebView view, int newProgress) {
mLastProgress = newProgress;
if (newProgress == 100) {
final int width = w.getWidth();
final float scale = (float) W / width;
final Bitmap bm =w.createSnapshot(W, H, scale);
imageview.setImageBitmap(bm);
}
}
}
}
On Fri, Mar 28, 2008 at 12:22 PM, rm123 <[EMAIL PROTECTED]> wrote:
>
> When you create a new window in the web browser supplied with the sdk
> how does it get a preview image that you see when switching windows. I
> know copyWindowBitmap() does not work and is possibly being taken out.
> I tried WebView.createSnapshot but thats giving me an image with a -1
> width and height. Is that not working as well?
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
Announcing the new M5 SDK!
http://android-developers.blogspot.com/2008/02/android-sdk-m5-rc14-now-available.html
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---