1 Star 0 Fork 0

TS_OHOS / SquareCamera

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

SquareCamera

本项目是基于开源项目boxme/SquareCamera进行harmonyos化的移植和开发的,可以通过github地址 追踪到原项目.

项目介绍

使用hos原生API实现的方形拍照库

项目名称:SquareCamera

所属系列:harmonyos的第三方组件适配移植

功能:使用hos原生API实现的方形拍照库

项目移植状态:未移植部分请参考changelog

调用差异:无

原项目GitHub地址:https://github.com/boxme/SquareCamera

支持功能

  • 前后摄像头切换
  • 退出保存闪光灯模式
  • 支持横竖屏拍照

安装教程

方式一:

  1. 下载源码编译squarecamera获取har并放置在需要使用该库的module的libs目录里
  2. 在module的build.gradle里配置
dependencies {
    ...
    implementation fileTree(dir: 'libs', include: ['*.jar', '*.har'])
    ...
}

方式二:

  1. 在根目录的build.gradle文件中添加mavenCentral()
   // Top-level build file where you can add configuration options common to all sub-projects/modules.
   ...
   buildscript {
       repositories {
           ...
           mavenCentral()
       }
       ...
   }
   
   allprojects {
       repositories {
           ...
           mavenCentral()
       }
   }
  1. 在module目录下的build.gradle文件中添加
   ...
   dependencies {
       ...
       implementation 'com.gitee.ts_ohos:squarecamera:1.0.1'
   }

使用说明

1. 检测是否有camera权限,如果没有则进行申请

    /**
     * 检测权限
     */
    private void checkPermissions() {
        if (verifySelfPermission(SystemPermission.CAMERA) != IBundleManager.PERMISSION_GRANTED) {
            requestPermissions();
        } else {
            //已有权限
        }
    }

    /**
     * 申请权限
     */
    private void requestPermissions() {
        String[] permissions = {
                SystemPermission.CAMERA
        };
        List<String> permissionFiltered = Arrays.stream(permissions)
                .filter(permission -> verifySelfPermission(permission) != IBundleManager.PERMISSION_GRANTED)
                .collect(Collectors.toList());
        requestPermissionsFromUser(permissionFiltered.toArray(new String[permissionFiltered.size()]), 0);
    }

2. 跳转到拍照界面

    private void launch() {
        Intent intent = new Intent();

        Operation operation = new Intent.OperationBuilder()
                .withDeviceId("")
                .withBundleName(getBundleName())
                .withAbilityName(CameraConstants.CAMERA_ABILITY_NAME) //需要跳转到的ability
                .build();

        intent.setOperation(operation);
        startAbilityForResult(intent, 0x100);
    }

3. 在onAbilityResult中监听返回的结果

    @Override
    protected void onAbilityResult(int requestCode, int resultCode, Intent resultData) {
        if (resultCode == CameraConstants.CAMERA_RESULT_CODE) {
            Uri uri = resultData.getUri();
            if (uri != null) {
                //获取拍照保存后的uri
            }
        }
    }

效果展示

demo运行效果

移植版本

Branches/master(aa1d02b on 23 Jul 2016)

版本迭代

  • v1.0.1 fix bugs
  • v1.0.0 ohos首次移植版本

License

Copyright (c) 2015 Ng Yang Yi,Desmond

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
The MIT License (MIT) Copyright (c) 2015 Ng Yang Yi,Desmond Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

使用hos原生API实现的方形拍照库 展开 收起
Java
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/ts_ohos/SquareCamera.git
git@gitee.com:ts_ohos/SquareCamera.git
ts_ohos
SquareCamera
SquareCamera
master

搜索帮助