Hi gjs,

Thanks for pointing that error. But that was a type error. Now I am
pasting the correct code here.


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

        WebView w = new WebView(this);
        w.loadUrl("http://www.yahoo.com";);
        Bitmap mBitmap          = null;
        ByteArrayOutputStream mByteArrayOpStream        = null;

        //get the picture from the webview
        Picture picture = w.capturePicture();

        //Create the new Canvas
        Canvas mCanvas = new Canvas();

        //Copy the view canvas to a bitmap
        try{
                //w.draw(mCanvas);
                //mCanvas.save();
                //picture.draw(mCanvas);
                mCanvas.drawPicture(picture);
                //int restoreToCount =mCanvas.save();
                //mCanvas.drawPicture(picture);
                //mCanvas.restore();
        }
        catch (Exception e) {
                e.printStackTrace();
        }

        mBitmap = Bitmap.createBitmap(w.getWidth(), w.getHeight
(),Config.ARGB_8888);
        mCanvas.drawBitmap(mBitmap, 0, 0, null);

        if(mBitmap!= null) {
                mByteArrayOpStream = new ByteArrayOutputStream();
                mBitmap.compress(Bitmap.CompressFormat.JPEG, 90,
mByteArrayOpStream);
                try {
                        fos = openFileOutput("yahoo.jpg", MODE_WORLD_WRITEABLE);
                        fos.write(mByteArrayOpStream.toByteArray());
                        fos.close();
                } catch (FileNotFoundException e) {
                        e.printStackTrace();
                } catch (IOException e) {
                        e.printStackTrace();
                }
        }

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


Thanks,
Ajeet Singh


On Sep 9, 12:29 pm, gjs <[email protected]> wrote:
> Hi,
>
> the code you posted refers to mBitmapScreenshotonce, how did you
> instantiate this, what is it content ? black maybe...
>
> your code also refers to screenshot but the only time you access is
> when you attempt to compress it into a byte array, what is it
> content ? black maybe...
>
> Regards
>
> PS you won't get much help here, if you can't be bothered to check
> your own code...
>
> On Sep 9, 4:40 pm, Ajeet Singh <[email protected]> wrote:
>
> > Hi All,
>
> > I am trying to get the webview's content on a bitmap so that i can
> > save it as a image. But I am unable to so. I am getting the BLACK
> > image save instead. All content is missing :(
>
> > Anybody can help me regarding this.
>
> > Here is my code
>
> > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> > //create a webview
> > WebView w = new WebView(this);
>
> > //Loads the url
> > w.loadUrl("http://www.yahoo.com";);
>
> > //After loading completely, take its picture
> > Picture picture = w.capturePicture();
>
> > //Create a new canvas
> > Canvas mCanvas = new Canvas();
>
> > //Draw the Picture into the Canvas
> > picture.draw(mCanvas);
>
> > //Create a Bitmap
> > Bitmap sreenshot = Bitmap.createBitmap(picture.getWidth(),
> > picture.getHeight(),Config.ARGB_8888);
>
> > //copy the content fron Canvas to Bitmap
> > mCanvas.drawBitmap(mBitmapScreenshot, 0, 0, null);
>
> > //Save the Bitmap to local filesystem
> > if(sreenshot != null) {
> >         ByteArrayOutputStream mByteArrayOpStream = new
> > ByteArrayOutputStream();
> >         screenshot.compress(Bitmap.CompressFormat.JPEG, 90,
> > mByteArrayOpStream);
> >         try {
> >                 fos = openFileOutput("yahoo.jpg",
> > MODE_WORLD_WRITEABLE);
> >                 fos.write(mByteArrayOpStream.toByteArray());
> >                 fos.close();
> >         } catch (FileNotFoundException e) {
> >                 e.printStackTrace();
> >         } catch (IOException e) {
> >                 e.printStackTrace();
> >         }
>
> > }
>
> > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> > Thanks,
> > AJ
>
>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to