第一種:5.0 之後開放了截圖的方法
if
(build.version.sdk_int >=21)
else
@override
protected
void
onactivityresult
(int requestcode,
int resultcode, intent data)}}
}private
void
parsedata
(intent data)},
300)
; mvirtualdisplay.
release()
; mvirtualdisplay = null;
}
第二種:使用 decorview
public
static bitmap capture
(activity activity)
public
static bitmap shotactivity
(activity ctx)
長截圖
scrollview 截圖
public
static bitmap shotscrollview
(scrollview scrollview)
bitmap = bitmap.
createbitmap
(scrollview.
getwidth()
, h, bitmap.config.rgb_565)
;final canvas canvas =
newcanvas
(bitmap)
; scrollview.
draw
(canvas)
;return bitmap;
}
listview 截圖
public
static bitmap shotlistview
(listview listview)
bitmap bigbitmap = bitmap.
createbitmap
(listview.
getmeasuredwidth()
, allitemsheight, bitmap.config.argb_8888)
; canvas bigcanvas =
newcanvas
(bigbitmap)
; paint paint =
newpaint()
;int iheight =0;
for(
int i =
0; i < bmps.
size()
; i++
)return bigbitmap;
}
recyclerview 截圖
public
static bitmap shotrecyclerview
(recyclerview view)
height += holder.itemview.
getmeasuredheight()
;}bigbitmap = bitmap.
createbitmap
(view.
getmeasuredwidth()
, height, bitmap.config.argb_8888)
; canvas bigcanvas =
newcanvas
(bigbitmap)
; drawable lbackground = view.
getbackground()
;if(lbackground instanceof
colordrawable
)for
(int i =
0; i < size; i++)}
return bigbitmap;
}
第三種 : 使用 screencap 命令
adb shell screencap -p /sdcard/sreenshot1.png
// 第四種:完美截圖(優雅的方案實現螢幕截圖,利用android 5.0之後的錄屏api實現截圖)
// 第五種:通過 /dev/graphics/fb0 獲取螢幕截圖
fileinputstream graphics = null;
trycatch
(filenotfoundexception e)
datainputstream dstream =
newdatainputstream
(graphics)
;dstream.
readfully
(piex)
;dstream.
close()
;int
colors =
newint
[screenheight * screenwidth]
;// 將rgb轉為色值
for(
int m =
0; m < colors.length; m++
)bitmap bitmap = bitmap.
createbitmap
(colors, screenwidth, screenheight, bitmap.config.argb_8888)
;
Android截圖分享
android截圖並進行分享應該是乙個比較好用的功能,可惜在應用中見的不多 1.截圖 準備截圖 public void prepareshoot imgpath rootpath if imgpathfile.equals imgpath colorgoshareimga.png else else...
Android截圖方式
2017.5.6安卓巴士全球開發者論壇 廈門站 這個初夏 小巴仔想和程式設計師哥哥去廈門玩耍 你來嗎?android截圖 android截圖的原理 獲取具體需要截圖的區域的bitmap,然後繪製在畫布上,儲存為後進行分享或者其它用途 在截圖功能中,有時需要擷取全屏的內容,有時需要擷取超過一屏的內容 ...
Android 實現截圖
android實現截圖功能,使用view的方法,得到以時間戳命名的png view view v.getrootview view.setdrawingcacheenabled true view.builddrawingcache bitmap bitmap1 view.getdrawingcac...