Sorry Sean,
That was a typo error. The looks like
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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 in Advance
AJ
On Sep 9, 9:39 pm, Sean Hodges <[email protected]> wrote:
> > //copy the content fron Canvas to Bitmap
> > mCanvas.drawBitmap(mBitmapScreenshot, 0, 0, null);
>
> What is mBitmapScreenshot? Where is it being set to anything?
>
> On Wed, Sep 9, 2009 at 6:50 AM, Ajeet Singh<[email protected]> wrote:
>
> > Hi Sean,
>
> > I have tried in the following way, but still I am getting black
> > picture :(
> > Can you please look into the code, and see where I am doing wrong.
>
> > Thanks for all your support.
>
> > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> > //create awebview
> >WebVieww = newWebView(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 in advance,
> > Ajeet Singh
>
> > On Sep 9, 9:26 am, Ajeet Singh <[email protected]> wrote:
> >> Hi Sean,
>
> >> Thanks for replying.
>
> >> I got the idea what exactly you want to say.
>
> >> The code does not work straight forward. It is crashing at drawing
> >> canvas fromwebview.
>
> >> w.draw(tempCanvas);
>
> >> If I comment this line it it saves yahoo.jpg file totally black in
> >> color. nothing comes out there.
>
> >> Let me try what is can be done to get the actual view of any site.
>
> >> Anyway thanks.
>
> >> Ajeet Singh
>
> >> 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:
>
> >> >WebVieww = newWebView(this);
> >> > w.loadUrl("http://www.yahoo.com");
>
> >> > // Copy the view canvas to a bitmap
> >> > Canvas tempCanvas = new Canvas();
> >> > w.draw(tempCanvas);
> >> > Bitmapscreenshot= 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 onewebview
> >> > >>WebVieww = newWebView(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);
> >> > >> > Bitmapscreenshot= 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 usescreenshotkind 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
>
>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---