1

I want to generate bitmap for webview full page.

some codes

Below code for generating Bitmap from webview
Webview to Bitmap :

  webview.measure(MeasureSpec.makeMeasureSpec(
                  MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED),
                  MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
          webview.layout(0, 0, webview.getMeasuredWidth(),
                  webview.getMeasuredHeight());
          webview.setDrawingCacheEnabled(true);
          webview.buildDrawingCache();
          Bitmap bm=null;
          try
          {
              Log.d("Measuredwidth", "MeasuredWidth"+webview.getMeasuredWidth());
              Log.d("Measuredheight", "Measuredheight"+webview.getMeasuredHeight());
              Log.d("Measuredheightandstate", "Measuredheight and state"+webview.getMeasuredHeightAndState());

              bm = Bitmap.createBitmap(webview.getMeasuredWidth(),
                  webview.getMeasuredHeight(), Bitmap.Config.ARGB_8888);
          }
          catch(OutOfMemoryError e)
          {
              e.printStackTrace();
                return null;
          }

          Canvas bigcanvas = new Canvas(bm);
          Paint paint = new Paint();
          int iHeight = bm.getHeight();
          bigcanvas.drawBitmap(bm, 0, iHeight, paint);
          webview.draw(bigcanvas);

below code for to save the file in memory for that

To save as file :

  if (bm != null) {
              try {
                  String path = Environment.getExternalStorageDirectory()
                          .toString();
                  OutputStream fOut = null;
                  File file = new File(path, "/aaaa.png");
                  fOut = new FileOutputStream(file);

                  bm.compress(Bitmap.CompressFormat.PNG, 50, fOut);
                  fOut.flush();
                  fOut.close();
                  bm.recycle();
              } catch (Exception e) {
                  e.printStackTrace();
              }
          }

Here my problem is webview loading completely but after saving as file bottom half not completely loading . i tried to get solution for this but failed. if any one have idea about this please help me.. Thanks in adavance

user512
  • 403
  • 4
  • 21
  • http://stackoverflow.com/questions/20942623/which-can-replace-capturepicture-function/20963109#20963109 & http://stackoverflow.com/questions/4633988/generate-bitmap-from-html-in-android – VVB Mar 23 '15 at 06:25
  • thanks for reply but pictureListener deprecated know.. – user512 Mar 23 '15 at 06:33
  • Better to have seperate question for this – VVB Mar 23 '15 at 06:35
  • actually i used same code from this(http://stackoverflow.com/questions/20942623/which-can-replace-capturepicture-function/20963109#20963109). – user512 Mar 23 '15 at 06:35
  • already some are posted about that then they refer above link.. – user512 Mar 23 '15 at 06:38
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/73553/discussion-between-user512-and-vvb). – user512 Mar 23 '15 at 06:38

0 Answers0