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

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

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

WebView.capturePicture介绍

暂无

代码示例

代码示例来源:origin: RobotiumTech/robotium

/**
 * Returns a bitmap of a given WebView.
 *  
 * @param webView the webView to save a bitmap from
 * @return a bitmap of the given web view
 * 
 */
private Bitmap getBitmapOfWebView(final WebView webView){
  Picture picture = webView.capturePicture();
  Bitmap b = Bitmap.createBitmap( picture.getWidth(), picture.getHeight(), Bitmap.Config.ARGB_8888);
  Canvas c = new Canvas(b);
  picture.draw(c);
  return b;
}

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

Picture picture = webview.capturePicture();

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

Picture picture = view.capturePicture();
Bitmap  b = Bitmap.createBitmap( picture.getWidth(),
picture.getHeight(), Bitmap.Config.ARGB_8888);

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

private void getSnapshot() {
  Picture picture = webView.capturePicture();
  int width = picture.getWidth();
  int height = picture.getHeight();
  if (width > 0 && height > 0) {
    Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    picture.draw(canvas);
    try {
      String fileName = Environment.getExternalStorageDirectory().getPath()+"/webview_capture1.jpg";
      FileOutputStream fos = new FileOutputStream(fileName);
      //压缩bitmap到输出流中
      bitmap.compress(Bitmap.CompressFormat.JPEG, 70, fos);
      fos.close();
      Toast.makeText(WebviewFromCapture.this, "截屏成功", Toast.LENGTH_LONG).show();
      bitmap.recycle();
    } catch (Exception e) {
      Log.e(TAG, e.getMessage());
    }
  }
}

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

webview.setWebViewClient(new WebViewClient() {

  @Override
  public void onPageFinished(WebView view, String url) {
    Picture picture = view.capturePicture();
    Bitmap b = Bitmap.createBitmap(
      picture.getWidth(), picture.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas c = new Canvas(b);
    picture.draw(c);

    FileOutputStream fos = null;
    try {
      fos = new FileOutputStream( "/sdcard/"  + "page.jpg" );
      if ( fos != null ) {
        b.compress(Bitmap.CompressFormat.JPEG, 90, fos );
        fos.close();
      }
    } 
    catch( Exception e ) {
      System.out.println("-----error--"+e);
    }
  }
});

webview.loadUrl("http://stackoverflow.com/questions/15351298/capturing-android-webview-image-and-saving-to-png-jpeg");

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

webView.setWebViewClient(new WebViewClient() {

  public void onPageFinished(WebView v, String url) {
    Picture picture = v.capturePicture();
    Bitmap bmp = Bitmap.createBitmap(
           picture.getWidth(), picture.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(b);
    picture.draw(canvas);
    imgView.setImageBitmap(bmp);      
}

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

WebView wv = new WebView(this);
wv.loadData("<html><body><p>Hello World</p></body></html>");
Picture p = wv.capturePicture();

代码示例来源:origin: com.jayway.android.robotium/robotium-solo

/**
 * Returns a bitmap of a given WebView.
 *  
 * @param webView the webView to save a bitmap from
 * @return a bitmap of the given web view
 * 
 */
private Bitmap getBitmapOfWebView(final WebView webView){
  Picture picture = webView.capturePicture();
  Bitmap b = Bitmap.createBitmap( picture.getWidth(), picture.getHeight(), Bitmap.Config.ARGB_8888);
  Canvas c = new Canvas(b);
  picture.draw(c);
  return b;
}

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

webViewToPrint.setWebViewClient(new WebViewClient()
 {
     public void onPageFinished(WebView view, String url)
     {
         Picture picture = view.capturePicture();
         Bitmap  b = Bitmap.createBitmap( picture.getWidth(),
         picture.getHeight(), Bitmap.Config.ARGB_8888);
         Canvas c = new Canvas( b );
         picture.draw( c );
         imageView.setImageBitmap(b);    }}

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

WebView webView = new WebView(this);
//your image is in webview

Picture picture = webView.capturePicture();
Canvas canvas = new Canvas();
picture.draw(canvas);
Bitmap image = Bitmap.createBitmap(picture.getWidth(),
picture.getHeight(),Config.ARGB_8888);
canvas.drawBitmap(mimage, 0, 0, null);
if(image != null) {
  ByteArrayOutputStream mByteArrayOS = new
  ByteArrayOutputStream();
  image.compress(Bitmap.CompressFormat.JPEG, 90, mByteArrayOS);
  try {
    fos = openFileOutput("image.jpg", MODE_WORLD_WRITEABLE);
    fos.write(mByteArrayOS.toByteArray());
    fos.close();
  } catch (FileNotFoundException e) {
    e.printStackTrace();
  } catch (IOException e) {
    e.printStackTrace();
  }
}

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

Picture p=web.capturePicture();
SharedPreferences prefs=con.getSharedPreferences("File_COUNT", con.MODE_PRIVATE);

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

w = new WebView(this); 
  w.setWebViewClient(new WebViewClient() 
  { 
      public void onPageFinished(WebView view, String url) 
      { 
          Picture picture = view.capturePicture(); 
      Bitmap  b = Bitmap.createBitmap( picture.getWidth(), 
picture.getHeight(), Bitmap.Config.ARGB_8888); 
      Canvas c = new Canvas( b ); 
      picture.draw( c ); 
      FileOutputStream fos = null; 
      try { 
          fos = new FileOutputStream( "/sdcard/yahoo_" + 
System.currentTimeMillis() + ".jpg" ); 
          if ( fos != null ) 
          { 
              b.compress(Bitmap.CompressFormat.JPEG, 90, fos ); 
              fos.close(); 
          } 
      } catch( Exception e ) 
          { 
          //... 
          } 
      } 
   });

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

Picture picture = webView.capturePicture();
Bitmap b = Bitmap.createBitmap(picture.getWidth(),picture.getHeight(), Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(b);

代码示例来源:origin: ckcz123/PKUHelper-Android

@SuppressWarnings("deprecation")
public static Bitmap captureWebView(WebView webView) {
  if (webView == null) return null;
  Picture snapShot = webView.capturePicture();
  Bitmap bmp = Bitmap.createBitmap(snapShot.getWidth(), snapShot.getHeight(), Bitmap.Config.ARGB_8888);
  Bitmap bg=null;
  try {
    Bitmap bgr = ((BitmapDrawable) webView.getBackground()).getBitmap();
    bg=Bitmap.createScaledBitmap(bgr, snapShot.getWidth(), snapShot.getHeight(), true);
  }
  catch (Exception | OutOfMemoryError e) {bg=null;}
  Canvas canvas = new Canvas(bmp);
  if (bg!=null)
    canvas.drawBitmap(bg,0,0,new Paint());
  snapShot.draw(canvas);
  return bmp;
}

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

Picture picture = w.capturePicture();

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

Picture picture = view.capturePicture();
Bitmap  b = Bitmap.createBitmap( picture.getWidth(),
picture.getHeight(), Bitmap.Config.ARGB_8888);

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

w.setWebViewClient(new WebViewClient(){
  public void onPageFinished(WebView view, String url){
    Picture picture = view.capturePicture();
    Bitmap  b = Bitmap.createBitmap( picture.getWidth(),
    picture.getHeight(), Bitmap.Config.ARGB_8888);

相关文章

微信公众号

最新文章

更多

WebView类方法