android.webkit.WebView.setDrawingCacheEnabled()方法的使用及代码示例

x33g5p2x  于2022-02-02 转载在 其他  
字(8.7k)|赞(0)|评价(0)|浏览(169)

本文整理了Java中android.webkit.WebView.setDrawingCacheEnabled()方法的一些代码示例,展示了WebView.setDrawingCacheEnabled()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WebView.setDrawingCacheEnabled()方法的具体详情如下:
包路径:android.webkit.WebView
类名称:WebView
方法名:setDrawingCacheEnabled

WebView.setDrawingCacheEnabled介绍

暂无

代码示例

代码示例来源:origin: airbnb/AirMapView

@Override public void getSnapshot(OnSnapshotReadyListener listener) {
  boolean isDrawingCacheEnabled = webView.isDrawingCacheEnabled();
  webView.setDrawingCacheEnabled(true);
  // copy to a new bitmap, otherwise the bitmap will be
  // destroyed when the drawing cache is destroyed
  // webView.getDrawingCache can return null if drawing cache is disabled or if the size is 0
  Bitmap bitmap = webView.getDrawingCache();
  Bitmap newBitmap = null;
  if (bitmap != null) {
   newBitmap = bitmap.copy(Bitmap.Config.RGB_565, false);
  }

  webView.destroyDrawingCache();
  webView.setDrawingCacheEnabled(isDrawingCacheEnabled);

  listener.onSnapshotReady(newBitmap);
 }
}

代码示例来源:origin: stackoverflow.com

webView.layout(0, 0, webView.getMeasuredWidth(),
    webView.getMeasuredHeight());
webView.setDrawingCacheEnabled(true);
webView.buildDrawingCache();
Bitmap bitmap = Bitmap.createBitmap(webView.getMeasuredWidth(),

代码示例来源:origin: androidquery/androidquery

wv.setDrawingCacheEnabled(true);

代码示例来源:origin: stackoverflow.com

webView.layout(0, 0, webView.getMeasuredWidth(),
    webView.getMeasuredHeight());
webView.setDrawingCacheEnabled(true);
webView.buildDrawingCache();
Bitmap bm = Bitmap.createBitmap(webView.getMeasuredWidth(),

代码示例来源:origin: stackoverflow.com

public static Bitmap getBitmapForVisibleRegion(WebView webview) {
  Bitmap returnedBitmap = null;
  webview.setDrawingCacheEnabled(true);
  returnBitmap = Bitmap.createBitmap(webview.getDrawingCache());
  webview.setDrawingCacheEnabled(false);
  return returnedBitmap;
}

代码示例来源:origin: stackoverflow.com

public Bitmap getBitmapFromWebView(WebView webView) {
  webView.setDrawingCacheEnabled(true);
  webView.buildDrawingCache(true);
  Bitmap bitmap = Bitmap.createBitmap(webview.getDrawingCache());
  webView.setDrawingCacheEnabled(false);
  return bitmap;
}

代码示例来源:origin: stackoverflow.com

public File getBitmapFromwebchartView(WebView view2) {
  File fi;
  if (view2 != null) {
    view2.setDrawingCacheEnabled(true);
    Bitmap b = view2.getDrawingCache();
    if (b != null) {
     try {
      fi = new File(Environment.getExternalStorageDirectory(), "Screenshot" + ".jpg");
      // write the bytes in file
      FileOutputStream fo;
      fo = new FileOutputStream(fi);
      b.compress(CompressFormat.JPEG, 95, fo);
     } catch (Exception e) {
      e.printStackTrace();
     }
    }
  }
  return fi;
}

代码示例来源:origin: stackoverflow.com

public File getBitmapFromwebchartView(WebView view2) {

File fi = null;

if (view2 != null) {
  view2.setDrawingCacheEnabled(true);
  Bitmap b = view2.getDrawingCache();
  if (b != null) {

    try {

      fi = new File(Environment.getExternalStorageDirectory(), "Screenshot" + ".jpg");
      //fi     = new File(Environment.getExternalStorageDirectory(),"Realitycheck" + ".jpg");

      // write the bytes in file
      FileOutputStream fo;

      fo = new FileOutputStream(fi);

      b.compress(CompressFormat.JPEG, 95, fo);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
}
return fi;
}

代码示例来源:origin: hsk256/WebviewCapture

private void initWebview() {
  WebSettings webSettings = webView.getSettings();
  webSettings.setJavaScriptEnabled(true);
  webSettings.setSupportZoom(true); //支持缩放
  webView.requestFocusFromTouch();
  webView.setDrawingCacheEnabled(true);
  webView.setWebViewClient(new WebViewClient() {
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
      view.loadUrl(url);
      return true;
    }
  });
  webView.loadUrl("http://www.baidu.com");
}

代码示例来源:origin: hsk256/WebviewCapture

private void initWebview() {
  WebSettings webSettings = webView.getSettings();
  webSettings.setJavaScriptEnabled(true);
  webSettings.setSupportZoom(true); //支持缩放
  webView.requestFocusFromTouch();
  webView.setDrawingCacheEnabled(true);
  webView.setWebViewClient(new WebViewClient() {
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
      view.loadUrl(url);
      return true;
    }
  });
  webView.loadUrl("http://www.baidu.com");
}

代码示例来源:origin: stackoverflow.com

protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  button = (Button) findViewById(R.id.button1);
  imgView = (ImageView) findViewById(R.id.imageview);
  webView = (WebView) findViewById(R.id.webview);
  webView.loadUrl("file:///android_asset/test.jpg");
  button.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View v) {
      imgView.setImageBitmap(getBitmapForVisibleRegion(webView));

    }
  });
}

public static Bitmap getBitmapForVisibleRegion(WebView webview) {
  Bitmap returnedBitmap = null;
  webview.setDrawingCacheEnabled(true);
  returnedBitmap = Bitmap.createBitmap(webview.getDrawingCache());
  webview.setDrawingCacheEnabled(false);
  return returnedBitmap;
}

代码示例来源:origin: stackoverflow.com

Sry replace the function with this code

public File getBitmapFromwebchartView(WebView view2) {
    if (view2 != null) {
      view2.setDrawingCacheEnabled(true);
      Bitmap b = view2.getDrawingCache();
      if (b != null) {

        try {

          fl = new File(Environment.getExternalStorageDirectory(),
              "Realitycheck" + ".jpg");

          // write the bytes in file
          FileOutputStream fo;

          fo = new FileOutputStream(fl);

          b.compress(CompressFormat.JPEG, 95, fo);
        } catch (Exception e) {
          e.printStackTrace();
        }
      }
    }
    return fl;
  }

代码示例来源:origin: stackoverflow.com

public File getBitmapFromwebchartView(WebView view2) {

  File fi;

  if (view2 != null) {
    view2.setDrawingCacheEnabled(true);
    Bitmap b = view2.getDrawingCache();
    if (b != null) {

      try {

        fi = new File(Environment.getExternalStorageDirectory(), "Screenshot" + ".jpg");
        //fi     = new File(Environment.getExternalStorageDirectory(),"Realitycheck" + ".jpg");

        // write the bytes in file
        FileOutputStream fo;

        fo = new FileOutputStream(fi);

        b.compress(CompressFormat.JPEG, 95, fo);
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }
  return fi;
}

代码示例来源:origin: stackoverflow.com

Use this Code to get the screen shot of web view

public File getBitmapFromwebchartView(WebView view2) {
    if (view2 != null) {
      view2.setDrawingCacheEnabled(true);
      Bitmap b = view2.getDrawingCache();
      if (b != null) {

        try {

          fl = new File(Environment.getExternalStorageDirectory(),
              "Realitycheck" + ".jpg");

          // write the bytes in file
          FileOutputStream fo;

          fo = new FileOutputStream(fl);

          newbitmap.compress(CompressFormat.JPEG, 95, fo);
        } catch (Exception e) {
          e.printStackTrace();
        }
      }
    }
    return fl;
  }
Use this code and get the required file stored in sdcard.

代码示例来源:origin: stackoverflow.com

WebView text = (WebView) view.findViewById(R.id.webview);
 text.setDrawingCacheEnabled(false);
 WebSettings settings = text.getSettings();
 settings.setDefaultTextEncodingName("utf-8");
 text.setBackgroundColor(Color.TRANSPARENT);
   if (Build.VERSION.SDK_INT >= 11) // Android v3.0+
     try {
     text.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
     } catch (Exception e) {
     }

代码示例来源:origin: stackoverflow.com

@Override
public void onClick(View v) {
  mWebView.setDrawingCacheEnabled(true);
    e.printStackTrace();
  mWebView.setDrawingCacheEnabled(false);

代码示例来源:origin: stackoverflow.com

public File getBitmapFromwebchartView(WebView view2) {
    if (view2 != null) {
      view2.setDrawingCacheEnabled(true);
      Bitmap b = view2.getDrawingCache();
      if (b != null) {

代码示例来源:origin: stackoverflow.com

public static Bitmap screenshot2(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 bitmap = Bitmap.createBitmap(webView.getMeasuredWidth(),
      webView.getMeasuredHeight(), Bitmap.Config.ARGB_8888);

  Canvas canvas = new Canvas(bitmap);
  Paint paint = new Paint();
  int iHeight = bitmap.getHeight();
  canvas.drawBitmap(bitmap, 0, iHeight, paint);
  webView.draw(canvas);
  return bitmap;
}

代码示例来源:origin: yoyiyi/bilisoleil

@SuppressLint("SetJavaScriptEnabled")
protected void initWebView() {
  WebClient webChromeClient = new WebClient();
  WebClientBase webViewClient = new WebClientBase();
  WebSettings webSettings = mWebView.getSettings();
  //设置js支持
  webSettings.setJavaScriptEnabled(true);
  // 设置支持javascript脚本
  webSettings.setJavaScriptCanOpenWindowsAutomatically(false);
  //设置缓存
  webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);
  webSettings.setDomStorageEnabled(true);
  webSettings.setGeolocationEnabled(true);
  webSettings.setUseWideViewPort(true);//关键点
  webSettings.setLoadWithOverviewMode(true);//全屏
  webSettings.setBuiltInZoomControls(true);// 设置显示缩放按钮
  webSettings.setSupportZoom(true);//支持缩放
  webSettings.setDisplayZoomControls(false);
  webSettings.setAppCacheEnabled(true);
  webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
  mWebView.setDrawingCacheEnabled(true);
  mWebView.getSettings().setBlockNetworkImage(true);
  mWebView.setWebViewClient(webViewClient);
  mWebView.requestFocus(View.FOCUS_DOWN);
  mWebView.getSettings().setDefaultTextEncodingName("UTF-8");
  mWebView.setWebChromeClient(webChromeClient);
  mWebView.loadUrl(mUrl);
}

代码示例来源:origin: com.googlecode.android-query/android-query

wv.setDrawingCacheEnabled(true);

相关文章

WebView类方法