Android截图功能代码
16lz
2021-01-26
IDevice device; AndroidDebugBridge bridge = AndroidDebugBridge.createBridge(); waitDeviceList(bridge); IDevice devices[] = bridge.getDevices(); device = devices[0];
private static void waitDeviceList(AndroidDebugBridge bridge) { int count = 0; while (bridge.hasInitialDeviceList() == false) { try { Thread.sleep(100); // 如果没有获得设备列表,则等待 ount++; } catch (InterruptedException e) {} if (count > 300) { // 设定时间超过300×100 ms的时候为连接超时 System.err.print("Time out"); break; } } }
if(rawScreen != null){ BufferedImage image = null; int width2 = landscape ? rawScreen.height : rawScreen.width; int height2 = landscape ? rawScreen.width : rawScreen.height; if (image == null) { image = new BufferedImage(width2,height2, BufferedImage.TYPE_INT_RGB); } else { if (image.getHeight() != height2 || image.getWidth() != width2) { image = new BufferedImage(width2, height2, BufferedImage.TYPE_INT_RGB); } } int index = 0; int indexInc = rawScreen.bpp >> 3; for (int y = 0; y < rawScreen.height; y++) { for (int x = 0; x < rawScreen.width; x++, index += indexInc) { int value = rawScreen.getARGB(index); if (landscape) image.setRGB(y, rawScreen.width - x - 1, value); else image.setRGB(x, y, value); } } ImageIO.write((RenderedImage)image,"PNG",new File("D:/temp.jpg")); }
更多相关文章
- 解决:The Genymotion virtual device could not obtain an IP ad
- Android实现网络访问
- [Android] 自定义Indeterminate ProgressBar颜色
- Android在诸如editText等组件设置输入法半屏幕显示的说明
- Android修改源代码控制永不锁屏
- 【android】访问web service(大概功能版)
- android聊天,存储聊天记录sqlite
- 将Android中DatePickerDialog中月份的中文变成数字
- android loading界面 及 处理