android 在webView里面截圖大概有四種方式,具體內(nèi)容如下
成都創(chuàng)新互聯(lián)主要從事網(wǎng)頁(yè)設(shè)計(jì)、PC網(wǎng)站建設(shè)(電腦版網(wǎng)站建設(shè))、wap網(wǎng)站建設(shè)(手機(jī)版網(wǎng)站建設(shè))、成都響應(yīng)式網(wǎng)站建設(shè)、程序開(kāi)發(fā)、網(wǎng)站優(yōu)化、微網(wǎng)站、小程序開(kāi)發(fā)等,憑借多年來(lái)在互聯(lián)網(wǎng)的打拼,我們?cè)诨ヂ?lián)網(wǎng)網(wǎng)站建設(shè)行業(yè)積累了豐富的網(wǎng)站設(shè)計(jì)、做網(wǎng)站、網(wǎng)站設(shè)計(jì)、網(wǎng)絡(luò)營(yíng)銷(xiāo)經(jīng)驗(yàn),集策劃、開(kāi)發(fā)、設(shè)計(jì)、營(yíng)銷(xiāo)、管理等多方位專(zhuān)業(yè)化運(yùn)作于一體。1.獲取到DecorView然后將DecorView轉(zhuǎn)換成bitmap然后寫(xiě)入到文件里面.
View view = getWindow().getDecorView(); Bitmap bitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); view.draw(canvas); Log.d(TAG,"bitmap--"+bitmap); try { String fileName = Environment.getExternalStorageDirectory().getPath()+"/webview_jietu.jpg"; FileOutputStream fos = new FileOutputStream(fileName); //壓縮bitmap到輸出流中 bitmap.compress(Bitmap.CompressFormat.JPEG, 70, fos); fos.close(); Toast.makeText(WebviewFromGetDecorView.this, "截屏成功", Toast.LENGTH_LONG).show(); } catch (Exception e) { Log.e(TAG, e.getMessage()); }finally { if(bitmap!=null) { bitmap.recycle(); } }