android webView如何设置截取图片大小
现应用webview编了个小程序,准备截取网页图片
可是使用Picture pic = webView.capturePicture(); 每次截取的图片是整个网页的,而我希望截取的是屏幕显示的区域,请问如何调整截取区域的大小呢?
cutButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Picture pic = webView.capturePicture(); int width = pic.getWidth(); int height = pic.getHeight(); if(width > 0 && height > 0) { Bitmap bmp = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bmp); pic.draw(canvas); try { String fileName = "sdcard/" + System.currentTimeMillis() + ".png"; FileOutputStream fos = new FileOutputStream(fileName); if(fos != null) { bmp.compress(Bitmap.CompressFormat.PNG, 90, fos); fos.close(); } Toast.makeText(getApplicationContext(), "截图成功,文件名是:" + fileName, Toast.LENGTH_SHORT).show(); } catch (Exception e) { e.printStackTrace(); } } } });