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

embedded/2025/2/4 17:04:52/

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

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

二、踩坑只有一个扇形

 

<?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/embedded/159522.html

相关文章

vector容器(详解)

本文最后是模拟实现全部讲解&#xff0c;文章穿插有彩色字体&#xff0c;是我总结的技巧和关键 1.vector的介绍及使用 1.1 vector的介绍 https://cplusplus.com/reference/vector/vector/&#xff08;vector的介绍&#xff09; 了解 1. vector是表示可变大小数组的序列容器。…

蓝桥杯嵌入式省赛lcd模版

LCD原理图 可以参考和使用官方的参考例程 配置完引脚后点击GENERATE CODE即可无需其他操作 将这两个头文件复制到 在给的案例路径下将lcd.c也复制到bsp路径下面 #include "my_main.h" uint8_t led_sta0x10; char text[30]; void LED_Disp(uint8_t dsLED) {HAL_GPIO…

49【服务器介绍】

服务器和你的电脑可以说是一模一样的&#xff0c;只不过用途不一样&#xff0c;叫法就不一样了 物理服务器和云服务器的区别 整台设备眼睛能够看得到的&#xff0c;我们一般称之为物理服务器。所以物理服务器是比较贵的&#xff0c;不是每一个开发者都能够消费得起的。 …

【Linux系统】—— make/makefile

【Linux系统】—— make/makefile 1 什么是 make/makefile2 第一版本makefile3 依赖关系和依赖方法4 清理4.1 清理的基本语法4.2 make 的默认执行4.3 为什么要加 『.PHONY:clean』4.3.1 『.PHONY:clean』的功能4.3.2 如何理解总是不被执行4.3.2 如何区分文件的新旧 5 第二版本m…

bat脚本实现自动化漏洞挖掘

bat脚本 BAT脚本是一种批处理文件&#xff0c;可以在Windows操作系统中自动执行一系列命令。它们可以简化许多日常任务&#xff0c;如文件操作、系统配置等。 bat脚本执行命令 echo off#下面写要执行的命令 httpx 自动存活探测 echo off httpx.exe -l url.txt -o 0.txt nuc…

mac连接linux服务器

1、mac连接linux服务器 # ssh -p 22 root192.168.1.152、mac指定密码连接linux服务器 (1) 先安装sshpass,下载后解压执行 ./configure && make && makeinstall https://sourceforge.net/projects/sshpass/ (2) 连接linux # sshpass -p \/\\\[\!\\wen12\$ s…

使用Express.js和SQLite3构建简单TODO应用的后端API

使用Express.js和SQLite3构建简单TODO应用的后端API 引言环境准备代码解析1. 导入必要的模块2. 创建Express应用实例3. 设置数据库连接4. 初始化数据库表5. 配置中间件6. 定义数据接口7. 定义路由7.1 获取所有TODO项7.2 创建TODO项7.3 更新TODO项7.4 删除TODO项 8. 启动服务器 …

C++ Primer 标准库vector

欢迎阅读我的 【CPrimer】专栏 专栏简介&#xff1a;本专栏主要面向C初学者&#xff0c;解释C的一些基本概念和基础语言特性&#xff0c;涉及C标准库的用法&#xff0c;面向对象特性&#xff0c;泛型特性高级用法。通过使用标准库中定义的抽象设施&#xff0c;使你更加适应高级…