Hi Ajeet,
what I'm doing is, I have created a menu item called "take screeshot", so when
i create that menuItem, following code will be executed, and the code is
exactly same as described by you. Exception is not thrown every time, but I
face frequently (as i said 5-6 times of every 10 attempts).
private void takeScreenshot() {
WebView w = (WebView)findViewById(R.id.screenshot);
w.setVisibility(View.VISIBLE);
w.setWebViewClient(new WebViewClient()
{
public void onPageFinished(WebView view, String url)
{
Picture picture = view.capturePicture();
Bitmap b=Bitmap.createBitmap(
picture.getWidth(),picture.getHeight(), Bitmap.Config.ARGB_8888);
Canvas c = new Canvas( b );
picture.draw( c );
FileOutputStream fos = null;
try {
fos = new FileOutputStream( "/sdcard/myimage.png" );
if ( fos != null )
{
b.compress(Bitmap.CompressFormat.JPEG, 90, fos );
fos.close();
}
} catch( Exception e ){}
}
});
w.loadUrl("http://www.yahoo.com");
}
________________________________
From: AJ <[email protected]>
To: Android Developers <[email protected]>
Sent: Wed, 7 October, 2009 6:31:02 PM
Subject: [android-developers] Re: How to take snapshots (Screen shots) of a web
page
Hi Umesh,
> A quick question, is it possible to accomplish this task in the background
> with without harming the present view (that is being displayed) ?
I think this is possible. You can create one thread and do all thing
in background.
> and also sometimes I get illigalArgument Exception for the following
> statement.
It looks like that the width and height of webview which we are
passing to Bitmap is zero. I don't know why unless and until I could
not see what exactly you are trying to do.
Temporarily you can put the check to avoid exception.
ublic void onPageFinished(WebView view, String url)
{
Picture picture = view.capturePicture();
if(picture.getWidth()> 0 &&picture.getHeight() > 0)
Bitmap b = Bitmap.createBitmap
( picture.getWidth(),picture.getHeight(), Bitmap.Config.ARGB_8888);
Hope this helps you
Thanks,
AJ
On Oct 7, 5:41 pm, Umesh <[email protected]> wrote:
> Hi Ajeet,
>
> A quick question, is it possible to accomplish this task in the background
> with without harming the present view (that is being displayed) ?
> and also sometimes I get illigalArgument Exception for the following
> statement.
>
> public void onPageFinished(WebView view, String url)
> {
> Picture picture = view.capturePicture();
> Bitmap b = Bitmap.createBitmap(
> picture.getWidth(),picture.getHeight(), Bitmap.Config.ARGB_8888);
> ..
> ...
>
> }
>
> Error Log:
>
> E/AndroidRuntime( 1141): Uncaught handler: thread main exiting due to
> uncaught exception
> E/AndroidRuntime( 1141): java.lang.IllegalArgumentException: width and height
> must be > 0
> E/AndroidRuntime( 1141): at
> android.graphics.Bitmap.nativeCreate(Native Method)
> E/AndroidRuntime( 1141): at
> android.graphics.Bitmap.createBitmap(Bitmap.java:483)
> E/AndroidRuntime( 1141):
> com.example.myproj.MyActivity$7.onPageFinished(WindRiver_WebHome.java:388)
> E/AndroidRuntime( 1141): at
> android.webkit.CallbackProxy.handleMessage(CallbackProxy.java:222)
> E/AndroidRuntime( 1141): at
> android.os.Handler.dispatchMessage(Handler.java:99)
>
> this happens frequently around 50% of deployment of the apk on emulator.
>
> Thanks
> umesh
>
> ________________________________
> From: AJ <[email protected]>
> To: Android Developers <[email protected]>
> Sent: Mon, 5 October, 2009 6:45:48 PM
> Subject: [android-developers] Re: How to take snapshots (Screen shots) of a
> web page
>
> This would work fine if you take snapshot of visible portion of
> webpage.
>
> Thanks,
> AJ
>
> On Oct 5, 6:11 pm, AJ <[email protected]> wrote:
>
>
>
>
>
> > Hi Umesh,
>
> > check the following link
>
> >http://groups.google.com/group/android-discuss/browse_thread/thread/c...
>
> > Thanks,
> > AJ
>
> > On Oct 5, 4:25 pm, Umesh <[email protected]> wrote:
>
> > > Hi all,
>
> > > I want to implement a functionality, wherein I need to take a snapshot
> > > (Screen Shot) of a web page opened in android browser, and store that
> > > image on sdcard . The image can be either in jpeg or png format. Can some
> > > one guide me with a piece of sample code as how to accomplish this.
>
> > > Thanks in advance.
> > > Umesh.
>
> > > Yahoo! India has a new look. Take a sneak
> > > peekhttp://in.yahoo.com/trynew
>
> Now, send attachments up to 25MB with Yahoo! India Mail. Learn
> how.http://in.overview.mail.yahoo.com/photos
Add whatever you love to the Yahoo! India homepage. Try now!
http://in.yahoo.com/trynew
--~--~---------~--~----~------------~-------~--~----~
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]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---