On Sep 8, 5:59 pm, Sean Hodges <[email protected]> wrote:
> Well, based on your example code, my suggestion is to do something like this:
>
> WebView w = new WebView(this);
> w.loadUrl("http://www.yahoo.com";);
>
> // Copy the view canvas to a bitmap
> Canvas tempCanvas = new Canvas();
> w.draw(tempCanvas);
> Bitmap screenshot = Bitmap.createBitmap(w.getWidth(), w.getHeight(),
> Config.ARGB_8888);
> tempCanvas.drawBitmap(screenshot, 0, 0, null);
>
> // Save to disk
> if(bmpBuffer != null) {
>     mByteArrayOpStream = new ByteArrayOutputStream();
>     bmpBuffer.compress(Bitmap.CompressFormat.JPEG, 90,
>     mByteArrayOpStream);
>     fos = openFileOutput("yahoo.jpg", MODE_WORLD_WRITEABLE);
>     fos.write(mByteArrayOpStream.toByteArray());
>     fos.close();
>
> }
>
> NOTE: I haven't tested this, it's only to describe what I meant.
> You'll probably need to tweak the code to make it work properly.On Tue, Sep 
> 8, 2009 at 6:49 AM, Ajeet Singh<[email protected]> wrote:
>
> > Any body  could you please share some info regarding this?
>
> > On Sep 7, 6:00 pm, Ajeet Singh <[email protected]> wrote:
> >> Thanks, sean for the quick reply.
>
> >> I did not get what exactly you want to say.(Sorry for that)
>
> >> Let me explain what i am trying to do.
>
> >> ################################### Code START
> >> ###################################
>
> >> // I have created one webview
> >> WebView w = new WebView(this);
> >> //Loaded yahoo
> >> w.loadUrl("http://www.yahoo.com";);
> >> //Capture the picture
> >> Picture picture = w.capturePicture();
> >> int mHeight = picture.getHeight();
> >> int mWidth = picture.getWidth();
>
> >> // created the Bitmap
> >> Bitmap bmpBuffer = Bitmap.createBitmap(mWidth, mHeight,
> >> Config.ARGB_8888);
>
> >> if(bmpBuffer != null) {
> >>     mByteArrayOpStream = new ByteArrayOutputStream();
> >>     bmpBuffer.compress(Bitmap.CompressFormat.JPEG, 90,
> >> mByteArrayOpStream);
>
> >>     fos = openFileOutput("yahoo.jpg", MODE_WORLD_WRITEABLE);
> >>     fos.write(mByteArrayOpStream.toByteArray());
> >>     fos.close();}
>
> >> ################################### Code END
> >> ###################################
>
> >> But when I see my image (yahoo.jpg) its an empty image. Nothing is
> >> there.
>
> >> After that i tried another method. there is one function
> >> getDrawingCache() which returns the Bitmap. But it is returning the
> >> Bitmap only of the visible area of the screen. (NOT the whole webpage)
>
> >> Any help would  be appreciated.
>
> >> Thanks in Advance,
> >> Ajeet Singh
>
> >> On Sep 7, 1:42 pm, Sean Hodges <[email protected]> wrote:
>
> >> > I've not done this before, but I believe you could create a new Canvas
> >> > object, and call the draw() method on your parent activity, passing in
> >> > your temp canvas object as the target:
>
> >> >http://developer.android.com/reference/android/view/View.html#draw%28...
>
> >> > Something similar to this:
>
> >> > Canvas tempCanvas = new Canvas();
> >> > this.draw(tempCanvas);
> >> > Bitmap screenshot = tempCanvas.drawBitmap(...)
>
> >> > After that, you should be able to call drawBitmap()  on the canvas,
> >> > and it will produce a "screenshiot" of everything inside that
> >> > activity.
>
> >> > On Mon, Sep 7, 2009 at 9:29 AM, Ajeet Singh<[email protected]> 
> >> > wrote:
>
> >> > > Actually I want to take screen-shot of what is shown on the screen as
> >> > > well as beyond it also like in case if scroll bar are present.
>
> >> > > There is one function getDrawingCache() which does that, but it only
> >> > > save picture what is available on the screen. It does not capture
> >> > > beyond screen if the picture is big.
>
> >> > > If some body knows then plz reply.
>
> >> > > Anyway, i will post this question to android-developer forum.
>
> >> > > Thanks gjs for your quick reply.
>
> >> > > Ajeet
>
> >> > > On Sep 7, 12:22 pm, gjs <[email protected]> wrote:
> >> > >> And this question is probably better asked in the developers group.
>
> >> > >>http://groups.google.com/group/android-developers
>
> >> > >> On Sep 7, 5:11 pm, gjs <[email protected]> wrote:
>
> >> > >> > Hi,
>
> >> > >> > Have a look at View.draw(Canvas canvas) in the 
> >> > >> > docshttp://developer.android.com/reference/android/view/View.html
>
> >> > >> > Create a Bitmap of an appropriate size and a Canvas which uses the
> >> > >> > Bitmap, call View.draw(canvas) - using your view - then save the
> >> > >> > Bitmap to file in whatever format jpg, png etc.
>
> >> > >> > It works for most but not all types of  views.
>
> >> > >> > Regards
>
> >> > >> > On Sep 7, 2:42 pm, Ajeet Singh <[email protected]> wrote:
>
> >> > >> > > I want to use screenshot kind of application in my own 
> >> > >> > > application. So
> >> > >> > > that I can take picture in any format and save it.
>
> >> > >> > > Can anybody give me hint what to use and how to start?
>
> >> > >> > > Thanks in advance,
> >> > >> > > Ajeet






hi....
well i tried the above code but

during runtime getting error:

10-22 12:58:44.339: ERROR/AndroidRuntime(3915): Uncaught handler:
thread main exiting due to uncaught exception
10-22 12:58:44.359: ERROR/AndroidRuntime(3915):
java.lang.RuntimeException: Unable to start activity ComponentInfo
{com.sshot/com.sshot.sshot}: java.lang.IllegalArgumentException: width
and height must be > 0
10-22 12:58:44.359: ERROR/AndroidRuntime(3915):     at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:
2268)
10-22 12:58:44.359: ERROR/AndroidRuntime(3915):     at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:
2284)
10-22 12:58:44.359: ERROR/AndroidRuntime(3915):     at
android.app.ActivityThread.access$1800(ActivityThread.java:112)
10-22 12:58:44.359: ERROR/AndroidRuntime(3915):     at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1692)
10-22 12:58:44.359: ERROR/AndroidRuntime(3915):     at
android.os.Handler.dispatchMessage(Handler.java:99)
10-22 12:58:44.359: ERROR/AndroidRuntime(3915):     at
android.os.Looper.loop(Looper.java:123)
10-22 12:58:44.359: ERROR/AndroidRuntime(3915):     at
android.app.ActivityThread.main(ActivityThread.java:3948)
10-22 12:58:44.359: ERROR/AndroidRuntime(3915):     at
java.lang.reflect.Method.invokeNative(Native Method)
10-22 12:58:44.359: ERROR/AndroidRuntime(3915):     at
java.lang.reflect.Method.invoke(Method.java:521)
10-22 12:58:44.359: ERROR/AndroidRuntime(3915):     at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run
(ZygoteInit.java:782)
10-22 12:58:44.359: ERROR/AndroidRuntime(3915):     at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:540)
10-22 12:58:44.359: ERROR/AndroidRuntime(3915):     at
dalvik.system.NativeStart.main(Native Method)
10-22 12:58:44.359: ERROR/AndroidRuntime(3915): Caused by:
java.lang.IllegalArgumentException: width and height must be > 0
10-22 12:58:44.359: ERROR/AndroidRuntime(3915):     at
android.graphics.Bitmap.nativeCreate(Native Method)
10-22 12:58:44.359: ERROR/AndroidRuntime(3915):     at
android.graphics.Bitmap.createBitmap(Bitmap.java:483)
10-22 12:58:44.359: ERROR/AndroidRuntime(3915):     at
com.sshot.sshot.onCreate(sshot.java:45)
10-22 12:58:44.359: ERROR/AndroidRuntime(3915):     at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:
1123)
10-22 12:58:44.359: ERROR/AndroidRuntime(3915):     at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:
2231)
10-22 12:58:44.359: ERROR/AndroidRuntime(3915):     ... 11 more


Any help would  be appreciated.

Thanks



my CODE is like this :

  public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        webview = (WebView) findViewById(R.id.webview);
       webview.getSettings().setJavaScriptEnabled(true);
       webview.loadUrl("http://www.google.com";);
        Log.d("sshot","@@@@@ Yahoo @@@@");

       //webview.setVisibility(View.VISIBLE);
        int mH=webview.getHeight();
        Log.d("sshot", "### Height ###"+   mH);
        Log.d("sshot","@@@@@ Yahoo1 @@@@");
    Picture picture=webview.capturePicture();
    Log.d("sshot", "### pic height ###"+   picture.getHeight());
   int mHeight=picture.getHeight();
    int mWidth=picture.getWidth();
    Log.d("sshot", "### mWidth ###"+   mWidth);
      // Copy the view canvas to a bitmap
    Log.d("sshot","@@@@@ Yahoo2 @@@@");
       Canvas tempCanvas = new Canvas();
       webview.draw(tempCanvas);
      Log.d("sshot","@@@@@ Yahoo3 @@@@");
//      if(picture.getWidth()>0)
//      {
     Bitmap screenshot = Bitmap.createBitmap
(mWidth,mHeight,   //////// mHeight and mWidth values are comin
0 ////////
     Config.ARGB_8888);
     Log.d("sshot","@@@@@ Yahoo4 @@@@");
         tempCanvas.drawBitmap(screenshot, 0, 0, null);

    //  Bitmap bmpBuffer;
                // Save to disk
        if(screenshot != null) {
             ByteArrayOutputStream mByteArrayOpStream = new
ByteArrayOutputStream();
             screenshot.compress(Bitmap.CompressFormat.JPEG, 90,
           mByteArrayOpStream);
            FileOutputStream fos = null;
                        try {
                                fos = openFileOutput("yahoo.jpg", 
MODE_WORLD_WRITEABLE);
                        } catch (FileNotFoundException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                        }
             try {
                                fos.write(mByteArrayOpStream.toByteArray());
                        } catch (IOException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                        }
           try {
                        fos.close();
                } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                }

       }

    }

}


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Android Discuss" 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-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to