android 圆形弹窗摄像头开发踩坑——源码————未来之窗跨平台操作

news/2025/2/2 8:59:22/

一、飘窗刷脸,拍照采用飘窗

刷脸认证安卓接口采用飘窗具有在不干扰用户主要操作的前提下以醒目方式引导用户完成认证,且能灵活定制样式以提升用户体验和认证效率的优点

二、踩坑只有一个扇形

 

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="100dp"android:layout_height="100dp"xmlns:app="http://schemas.android.com/apk/res-auto"><androidx.cardview.widget.CardViewandroid:id="@+id/popfacebgcard2"android:layout_width="280dp"android:layout_height="280dp"app:cardCornerRadius="280dp"android:layout_gravity="center"></androidx.cardview.widget.CardView></FrameLayout>

三、方形改圆形

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="100dp"android:layout_height="100dp"xmlns:app="http://schemas.android.com/apk/res-auto"><androidx.cardview.widget.CardViewandroid:id="@+id/popfacebgcard2"android:layout_width="280dp"android:layout_height="280dp"app:cardCornerRadius="280dp"android:layout_gravity="center"></androidx.cardview.widget.CardView></FrameLayout>

  app:cardCornerRadius="280dp"

四、通用圆形

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="296dp"android:layout_height="296dp"xmlns:app="http://schemas.android.com/apk/res-auto"><androidx.cardview.widget.CardViewandroid:id="@+id/popfacebgcard2"android:layout_width="280dp"android:layout_height="280dp"app:cardCornerRadius="280dp"android:layout_gravity="center"><TextureViewandroid:id="@+id/textureView"android:layout_width="fill_parent"android:layout_height="fill_parent"/></androidx.cardview.widget.CardView></FrameLayout>

 五、加外框

六、圆形外框

 

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="296dp"android:layout_height="296dp"xmlns:app="http://schemas.android.com/apk/res-auto"><androidx.cardview.widget.CardViewandroid:id="@+id/popfacebgcard"android:layout_width="296dp"android:layout_height="296dp"app:cardCornerRadius="296dp"android:background="#0078D7"><androidx.cardview.widget.CardViewandroid:id="@+id/popfacebgcard2"android:layout_width="280dp"android:layout_height="280dp"app:cardCornerRadius="280dp"android:layout_gravity="center"><!--<LinearLayoutandroid:id="@+id/popfacebg"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"android:background="@drawable/face_border">
--><TextureViewandroid:id="@+id/textureView"android:layout_width="fill_parent"android:layout_height="fill_parent"/><TextViewandroid:layout_width="match_parent"android:layout_height="match_parent"android:text="智慧押金"></TextView><!--</LinearLayout>--></androidx.cardview.widget.CardView></androidx.cardview.widget.CardView><!--<View        android:id="@+id/circularPopupView"android:layout_width="match_parent"android:layout_height="match_parent"><SurfaceViewandroid:id="@+id/surfaceViewInPopup"android:layout_width="match_parent"android:layout_height="match_parent" /></View>--></FrameLayout>

七、弹窗

 private void showPopup() {LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);popupView = inflater.inflate(R.layout.cyberwin_popup_face_layout, null);Context cyberwincpu=this;//  circularPopupView = popupView.findViewById(R.id.circularPopupView);// surfaceViewInPopup = popupView.findViewById(R.id.surfaceViewInPopup);// surfaceHolderInPopup = surfaceViewInPopup.getHolder();// surfaceHolderInPopup.addCallback(this);textureView = popupView.findViewById(R.id.textureView);//  LinearLayout popfacebg背景   = popupView.findViewById(R.id.popfacebg);CardView popfacebg背景2   = popupView.findViewById(R.id.popfacebgcard);WindowManager.LayoutParams params = new WindowManager.LayoutParams(WindowManager.LayoutParams.WRAP_CONTENT,WindowManager.LayoutParams.WRAP_CONTENT,WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY,WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE| WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL| WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH,PixelFormat.TRANSLUCENT);WindowManager.LayoutParams params小窗口 = new WindowManager.LayoutParams(DensityUtils.dp2px(this, 296),DensityUtils.dp2px(this, 296),WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY,WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE| WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL| WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH,PixelFormat.TRANSLUCENT);params小窗口.format = PixelFormat.RGBA_8888;//设置图片格式params.gravity = Gravity.CENTER;// 创建圆角背景//  GradientDrawable drawable = new GradientDrawable();//  drawable.setColor(Color.RED); // 设置背景颜色// drawable.setCornerRadius(100); // 设置圆角半径
/*if (popupView instanceof LinearLayout) {((LinearLayout) popupView).setBackground(drawable);}*///  ((LinearLayout) popupView).setBackground(drawable);// circularPopupView.setBackground(drawable);
/*// 将圆角背景设置为悬浮窗口的背景if (popupView instanceof LinearLayout) {((LinearLayout) popupView).setBackground(drawable);}*/// 当 TextureView 可用时,打开摄像头//  ViewGroup.LayoutParams layoutParams摄像头 = textureView.getLayoutParams();//  ViewGroup.LayoutParams layoutParams摄像头背景 = popfacebg背景2.getLayoutParams();// 设置宽度为 400 像素//  layoutParams摄像头.width = 350;// 设置高度为 600 像素//  layoutParams摄像头.height = 350;// popfacebg背景2.setCardr// popfacebg背景2.setLayoutParams(layoutParams摄像头背景);// 设置宽度为 400 像素// layoutParams摄像头.width = 350;// 设置高度为 600 像素// layoutParams摄像头.height = 350;// 应用新的布局参数// textureView.setLayoutParams(layoutParams摄像头);int paddingLeftInPx =  DensityUtils.dp2px(this, 8);//  popfacebg背景2.setPadding(paddingLeftInPx, paddingLeftInPx, paddingLeftInPx, paddingLeftInPx);// popfacebg背景2.setBackgroundColor(Color.parseColor("#0078D7"));textureView.setSurfaceTextureListener(new TextureView.SurfaceTextureListener() {@Overridepublic void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {// openCamera();//  Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)//    .setAction("Action", null)//    .setAnchorView(R.id.fab).show();Toast.makeText(cyberwincpu,"显示界面",Toast.LENGTH_SHORT);// drawCircle(textureView);打开摄像头(textureView);}@Overridepublic void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) {}@Overridepublic boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {return false;}@Overridepublic void onSurfaceTextureUpdated(SurfaceTexture surface) {}});windowManager.addView(popupView, params小窗口);//  popupView//  circularPopupView.setOnTouchListener(new View.OnTouchListener() {// popupView.setOnTouchListener(new View.OnTouchListener() {//  circularPopupView.setOnTouchListener(new View.OnTouchListener() {popupView.setOnTouchListener(new View.OnTouchListener() {int initialX, initialY;int initialTouchX, initialTouchY;@Overridepublic boolean onTouch(View v, MotionEvent event) {switch (event.getAction()) {case MotionEvent.ACTION_DOWN:initialX = params小窗口.x;initialY = params小窗口.y;initialTouchX = (int) event.getRawX();initialTouchY = (int) event.getRawY();return true;case MotionEvent.ACTION_UP:return true;case MotionEvent.ACTION_MOVE:params小窗口.x = initialX + (int) (event.getRawX() - initialTouchX);params小窗口.y = initialY + (int) (event.getRawY() - initialTouchY);drawCircle(popupView);windowManager.updateViewLayout(popupView, params小窗口);return true;}return false;}});}

八、摄像头
 

 private android.hardware.Camera camera摄像头;private void 打开摄像头(TextureView tv) {try {int cameraId = 仙盟_冥界_摄像头_寻找前置();if (cameraId != -1) {camera摄像头 = android.hardware.Camera.open(cameraId);}else{camera摄像头 = android.hardware.Camera.open();// cameraId=0;}android.hardware.Camera.Parameters parameters = camera摄像头.getParameters();android.hardware.Camera.Size previewSize = parameters.getPreviewSize();android.hardware.Camera.Size pictureSize = parameters.getPictureSize();camera摄像头.setDisplayOrientation(90);//注意顺序camera摄像头.setParameters(parameters);camera摄像头.setPreviewTexture(tv.getSurfaceTexture());camera摄像头.startPreview();//// 设置相机的预览方向//   setCameraDisplayOrientation(this, cameraId, camera摄像头);} catch (Exception e) {e.printStackTrace();}}private int 仙盟_冥界_摄像头_寻找前置() {int cameraCount = android.hardware.Camera.getNumberOfCameras();android.hardware.Camera.CameraInfo cameraInfo = new android.hardware.Camera.CameraInfo();for (int i = 0; i < cameraCount; i++) {android.hardware.Camera.getCameraInfo(i, cameraInfo);if (cameraInfo.facing == android.hardware.Camera.CameraInfo.CAMERA_FACING_FRONT) {return i;}}return -1;}// 设置相机的预览方向public  void setCameraDisplayOrientation(Context context, int cameraId, Camera camera) {try{Camera.CameraInfo info = new Camera.CameraInfo();Camera.getCameraInfo(cameraId, info);WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);int rotation = windowManager.getDefaultDisplay().getRotation();int degrees = 0;switch (rotation) {case android.view.Surface.ROTATION_0:degrees = 0;break;case android.view.Surface.ROTATION_90:degrees = 90;break;case android.view.Surface.ROTATION_180:degrees = 180;break;case android.view.Surface.ROTATION_270:degrees = 270;break;}int result;if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {result = (info.orientation + degrees) % 360;result = (360 - result) % 360;  // 前置摄像头需要镜像处理} else {  // 后置摄像头result = (info.orientation - degrees + 360) % 360;}camera.setDisplayOrientation(result);} catch (Exception e) {e.printStackTrace();Toast.makeText(this,"设置相机的预览方向"+e.getMessage(),Toast.LENGTH_SHORT);}}private void releaseCamera() {if (camera摄像头 != null) {camera摄像头.stopPreview();camera摄像头.release();camera摄像头 = null;}}


http://www.ppmy.cn/news/1568652.html

相关文章

第27篇:Python开发进阶:python多线程与多进程编程

第27篇&#xff1a;多线程与多进程编程 目录 并发编程概述 什么是并发编程多线程与多进程的区别 多线程编程 线程的基本概念创建和管理线程线程同步与锁 多进程编程 进程的基本概念创建和管理进程进程间通信 线程与进程的比较全局解释器锁&#xff08;GIL&#xff09; GIL的影…

【MySQL】数据类型与表约束

目录 数据类型分类 数值类型 tinyint类型 bit类型 小数类型 字符串类型 日期和时间类型 enum和set 表的约束 空属性 默认值 列描述 zerofill 主键 自增长 唯一键 外键 数据类型分类 数值类型 tinyint类型 MySQL中&#xff0c;整形可以是有符号和无符号的&…

pytorch实现门控循环单元 (GRU)

人工智能例子汇总&#xff1a;AI常见的算法和例子-CSDN博客 特性GRULSTM计算效率更快&#xff0c;参数更少相对较慢&#xff0c;参数更多结构复杂度只有两个门&#xff08;更新门和重置门&#xff09;三个门&#xff08;输入门、遗忘门、输出门&#xff09;处理长时依赖一般适…

【机器学习理论】生成模型和判别模型

生成模型和判别模型是机器学习中两种不同的建模方式。生成模型关注的是联合概率分布 P ( X , Y ) P(X, Y) P(X,Y)&#xff0c;即同时考虑数据 X X X和标签 Y Y Y的关系&#xff1b;判别模型则直接学习条件概率 P ( Y ∣ X ) P(Y|X) P(Y∣X)或决策边界。 生成模型 生成模型的目…

Vue3 结合 .NetCore WebApi 前后端分离跨域请求简易实例

1、本地安装Vue3环境 参考&#xff1a;VUE3中文文档-快速上手 注意&#xff1a;初始安装vue时&#xff0c;需要安装router&#xff0c;否则后续也要安装 2、安装axios组件 比如&#xff1a;npm install axioslatest 或 pnpm install axioslatest 3、设置跨域请求代理 打开…

【玩转全栈】----Django模板的继承

先赞后看&#xff0c;养成习惯&#xff01;&#xff01;&#xff01; 目录 模板继承的好处 模板继承的语法规则 更新代码 上文中的部门管理页面&#xff1a; 【玩转全栈】----Django制作部门管理页面-CSDN博客 大家会发现&#xff0c;由于定义了多个html文件&#xff0c;多个ht…

【精选】基于数据挖掘的招聘信息分析与市场需求预测系统 职位分析、求职者趋势分析 职位匹配、人才趋势、市场需求分析数据挖掘技术 职位需求分析、人才市场趋势预测

博主介绍&#xff1a; ✌我是阿龙&#xff0c;一名专注于Java技术领域的程序员&#xff0c;全网拥有10W粉丝。作为CSDN特邀作者、博客专家、新星计划导师&#xff0c;我在计算机毕业设计开发方面积累了丰富的经验。同时&#xff0c;我也是掘金、华为云、阿里云、InfoQ等平台…

青少年编程与数学 02-008 Pyhon语言编程基础 09课题、布尔与判断语句

青少年编程与数学 02-008 Pyhon语言编程基础 09课题、布尔与判断语句 一、布尔类型特点布尔运算符布尔函数应用场景 二、条件语句基本if语句if-elif-else语句示例条件表达式逻辑运算符嵌套if语句单行if语句 三、练习 课题摘要:本文介绍了Python中的布尔类型和条件语句。布尔类型…