关于MediaProjection的问题

风的泪 2016-07-22 05:25:35
写了一个app来投影,用了MediaProjection的createVirtualDisplay(String name, int width, int height, int dpi, int flags, Surface surface, VirtualDisplay.Callback callback, Handler handler),文档说明就一句话: Creates a VirtualDisplay to capture the contents of the screen. 这个意思应该就是数据源是screen吧,现在我只想要抓取我APP内部的视图,该怎么做呢?

现在大部分android手机取消物理按键,那三个键都显示在屏幕上了,我不想要投影这三个键,该怎么设置啊?

还有这个flag,我不太看得懂了,下面几个flag我都一一试过了,投影过去的东西没有任何差别。
VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR
Virtual display flag: Allows content to be mirrored on private displays when no content is being shown.
int VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY
Virtual display flag: Only show this display's own content; do not mirror the content of another display.
int VIRTUAL_DISPLAY_FLAG_PRESENTATION
Virtual display flag: Create a presentation display.
int VIRTUAL_DISPLAY_FLAG_PUBLIC
Virtual display flag: Create a public display.
int VIRTUAL_DISPLAY_FLAG_SECURE
Virtual display flag: Create a secure display.
...全文
545 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
风的泪 2016-07-25
  • 打赏
  • 举报
回复
问题又来了,我想获取底部模块物理按键的高度失败了,用了几种方法如下: 1、wm= (WindowManager) this.getSystemService(Context.WINDOW_SERVICE); int height = wm.getDefaultDisplay().getHeight(); int width = wm.getDefaultDisplay().getWidth(); 2、Resources resources = this.getResources(); DisplayMetrics dm = resources.getDisplayMetrics(); mWidth = dm.widthPixels; mHeight = dm.heightPixels; 3、mView = this.getWindow().getDecorView(); mView.getHeight(); mView.getWidth(); 4、mLayout = (RelativeLayout)findViewById(R.id.layout); //get my layout view mLayout.getWidth(); mLayout.getHeight(); 然后结果是这样的: 1、有模拟物理按键的时候: screen : height: 1080, width: 1794 dm.height = 1080width = 1794 mView.height = 1080, width = 1794 mLayout: height: 1005, width: 1794 2、没有物理按键的时候: screen : height: 1080, width: 1794 dm.height = 1080width = 1794 mView.height = 1080, width = 1920 mLayout: height: 1080, width: 1920 官方给的大小应该是1920×1080的,APP设置的是横屏状态,从结果来看,第1和2的结果按理应该是屏幕的信息,但现在我可不可以认为是错误的,然后3、4的信息应该是对了,但我想创建视图后就可以获取这样的信息,而不是收起那个按键后才获取到这个信息。 然后 我用的华为mate7,结果是这样的: 1、有模拟物理按键的时候: screen : height: 1080, width: 1794 dm.height = 1080width = 1794 mView.height = 1080, width = 1794 mLayout: height: 1005, width: 1794 2、没有物理按键的时候: screen : height: 1080, width: 1920 dm.height = 1080width = 1794 mView.height = 1080, width = 1920 mLayout: height: 1080, width: 1920 官方给的大小应该是1920×1080的
风的泪 2016-07-25
  • 打赏
  • 举报
回复
引用 1 楼 qq_28937033 的回复:
截取view内容,canvas.drawBitmap 或者自己裁剪createVirtualDisplay的内容
thank you, 我用了截取的方法,draw的还不太会用,哈哈,后面再看看
qq_28937033 2016-07-23
  • 打赏
  • 举报
回复
写错了 截取view内容,view.draw(canvas)
qq_28937033 2016-07-23
  • 打赏
  • 举报
回复
截取view内容,canvas.drawBitmap 或者自己裁剪createVirtualDisplay的内容

80,348

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧