保存webview后文件未完全加载到android中

时间:2015-03-23 06:00:51

标签: android webview bitmap

我想为webview整页生成位图。

一些代码

下面用于从webview生成位图的代码
  Webview到位图:

  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);

下面的代码,用于将文件保存到内存中

保存为文件:

  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();
              }
          }

这里我的问题是webview加载完全但在保存为文件下半部分没有完全加载。        我试图为此获得解决方案,但失败了。  如果有人对此有所了解,请帮助我..谢谢你的支持

0 个答案:

没有答案