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

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

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

WebView.draw介绍

暂无

代码示例

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

int height = bitmap.getHeight();
canvas.drawBitmap(bitmap, 0, height, paint);
webView.draw(canvas);

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

webView.getHeight(), Bitmap.Config.ARGB_8888);
final Canvas c = new Canvas(bmp);
webView.draw(c);

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

int iHeight = bm.getHeight();
bigcanvas.drawBitmap(bm, 0, iHeight, paint);
webView.draw(bigcanvas);
System.out.println("1111111111111111111111="
    + bigcanvas.getWidth());

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

private WebView mWebView;
public void onSavePhoto(int top, int left, int width, int height){
  Bitmap bitmap = Bitmap.createBitmap(mWebView.getWidth(), mWebView.getHeight(), Bitmap.Config.ARGB_8888);
  Canvas canvas = new Canvas(bitmap);
  mWebView.draw(canvas);

  // crop bitmap:
  Bitmap croppedBitmap = Bitmap.createBitmap(bitmap, left, top, width, height);
}

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

public class MainActivity extends Activity {
  private WebView mWebView;
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mWebView = new WebView(this);
    setContentView(mWebView);
    mWebView.loadUrl("http://tea.ch");
  }
  @Override
  public boolean onKeyDown(int keyCode, KeyEvent event) {
   if (keyCode != KeyEvent.KEYCODE_BACK) return super.onKeyDown(keyCode, event);
   Bitmap bm = Bitmap.createBitmap(200, 300, Bitmap.Config.ARGB_8888);
   Canvas c = new Canvas(bm);
   mWebView.draw(c);
   OutputStream stream = null;
   try {
    stream = new FileOutputStream(Environment.getExternalStorageDirectory() +"/teach.png");
    bm.compress(CompressFormat.PNG, 80, stream);
    if (stream != null) stream.close();
   } catch (IOException e) {
   } finally {
    bm.recycle();
   }
 <br>
 return super.onKeyDown(keyCode, event);
  }
}
 </br>

代码示例来源:origin: com.albedinsky.android/ui

/**
 */
@Override
public void draw(Canvas canvas) {
  super.draw(canvas);
  this.ensureDecorator();
  mDecorator.draw(canvas);
}

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

/**
 * 获得快照
 */
private void getSnapshot() {
    float scale = webView.getScale();
    int webViewHeight = (int) (webView.getContentHeight()*scale+0.5);
    Bitmap bitmap = Bitmap.createBitmap(webView.getWidth(),webViewHeight, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    webView.draw(canvas);
    try {
      String fileName = Environment.getExternalStorageDirectory().getPath()+"/webview_capture2.jpg";
      FileOutputStream fos = new FileOutputStream(fileName);
      //压缩bitmap到输出流中
      bitmap.compress(Bitmap.CompressFormat.JPEG, 70, fos);
      fos.close();
      Toast.makeText(WebviewFromDraw.this, "截屏成功", Toast.LENGTH_LONG).show();
      bitmap.recycle();
    } catch (Exception e) {
      Log.e(TAG, e.getMessage());
    }
}

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

/**
 * WevView screenshot
 * 
 * @param webView
 * @return
 */
public static Bitmap screenshot(WebView webView, float scale11) {
  try {
    float scale = webView.getScale();
    int height = (int) (webView.getContentHeight() * scale + 0.5);
    Bitmap bitmap = Bitmap.createBitmap(webView.getWidth(), height, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    webView.draw(canvas);
    return bitmap;
  } catch (Exception e) {
    e.printStackTrace();
  }
  return null;
}

代码示例来源:origin: hylinux1024/Componentization

/**
 * Convert view to an image.  Can be used to make animations smoother.
 *
 * @param context           The current Context or Activity that this method is called from
 * @param viewToBeConverted View to convert to a Bitmap
 * @return Bitmap object that can be put in an ImageView.  Will look like the converted viewToBeConverted.
 */
public static Bitmap viewToImage(Context context, WebView viewToBeConverted) {
  int extraSpace = 2000; //because getContentHeight doesn't always return the full screen height.
  int height = viewToBeConverted.getContentHeight() + extraSpace;
  Bitmap viewBitmap = Bitmap.createBitmap(viewToBeConverted.getWidth(), height, Bitmap.Config.ARGB_8888);
  Canvas canvas = new Canvas(viewBitmap);
  viewToBeConverted.draw(canvas);
  //If the view is scrolled, cut off the top part that is off the screen.
  try {
    int scrollY = viewToBeConverted.getScrollY();
    if (scrollY > 0) {
      viewBitmap = Bitmap.createBitmap(viewBitmap, 0, scrollY, viewToBeConverted.getWidth(), height - scrollY);
    }
  } catch (Exception ex) {
    Log.e("PercolateAndroidUtils", "Could not remove top part of the webview image.  ex=" + ex);
  }
  return viewBitmap;
}

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

wv.draw(canvas);
canvas.scale(1f, 1f);
canvas.drawRect(0, 0, canvas.getWidth()-1,  canvas.getHeight()-1, paint);

代码示例来源:origin: LonamiWebs/Stringlate

/**
 * Create a picture out of {@link WebView}'s whole content
 *
 * @param webView The WebView to get contents from
 * @return A {@link Bitmap} or null
 */
@Nullable
public static Bitmap getBitmapFromWebView(WebView webView) {
  try {
    //Measure WebView's content
    int widthMeasureSpec = View.MeasureSpec.makeMeasureSpec(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
    int heightMeasureSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
    webView.measure(widthMeasureSpec, heightMeasureSpec);
    webView.layout(0, 0, webView.getMeasuredWidth(), webView.getMeasuredHeight());
    //Build drawing cache and store its size
    webView.buildDrawingCache();
    int measuredWidth = webView.getMeasuredWidth();
    int measuredHeight = webView.getMeasuredHeight();
    //Creates the bitmap and draw WebView's content on in
    Bitmap bitmap = Bitmap.createBitmap(measuredWidth, measuredHeight, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    canvas.drawBitmap(bitmap, 0, bitmap.getHeight(), new Paint());
    webView.draw(canvas);
    webView.destroyDrawingCache();
    return bitmap;
  } catch (Exception | OutOfMemoryError e) {
    e.printStackTrace();
    return 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: zhangke3016/GeneratePicture

/**
 * 截屏
 *
 * @return
 */
public Bitmap getScreen() {
  Bitmap bmp = Bitmap.createBitmap(webView.getWidth(), 1, Bitmap.Config.ARGB_8888);
  int rowBytes = bmp.getRowBytes();
  bmp = null;
  if (rowBytes*webView.getHeight()>=getAvailMemory()){
    return null;
  }
  bmp = Bitmap.createBitmap(webView.getWidth(), webView.getHeight(), Bitmap.Config.ARGB_8888);
  Canvas canvas = new Canvas(bmp);
  webView.draw(canvas);
  return bmp;
}
@Override

相关文章

WebView类方法