MIT License

项目介绍

hzitoun/android-camera2-secret-picture-taker 是一个托管在 GitHub 上的开源项目,主要使用 Java 编写,采用 MIT License 许可证,目前获得 329 个 Star、83 次 Fork。

仓库全名
hzitoun/android-camera2-secret-picture-taker
开源许可证
MIT License
Star 数
329
Fork 数
83
未关闭 Issue
13

README 摘要

📸 Android Camera2 Secret Picture Taker (AC2SPT) Take pictures secretly (without preview or launching device's camera app) from all available cameras using Android CAMERA2 API. The Camera2 API replaces the deprecated Camera class. How can I support this project? If you have enjoyed the project and it helped you creating a project, building an app, starting a business. You could encourage and support me on patreon…

完整内容见 GitHub 原始 README 或本页 。

常见问题

android-camera2-secret-picture-taker 用什么语言开发?

主要使用 Java 编写,采用 MIT License 许可证,目前有 329 个 Star。

android-camera2-secret-picture-taker 可以免费商用吗?

仓库采用 MIT License 许可证,可免费使用与修改,商业使用请遵守许可证条款(例如保留版权声明与许可声明)。

如何获取 android-camera2-secret-picture-taker 的源码?

可以直接克隆仓库:git clone https://github.com/hzitoun/android-camera2-secret-picture-taker.git,默认分支为 master;安装与运行步骤见仓库 README。

android-camera2-secret-picture-taker 最近还在维护吗?

仓库最近一次更新为 2022年3月23日,当前有 13 个未关闭 Issue;Star 数为 329,可作为社区活跃度的参考。

关于

Take pictures 📷 secretly (without preview or launching device's camera app) using Android CAMERA2 API

描述取自 GitHub 官方 API,中文内容由 GitRead 中文社区 编辑团队整理。

简要分析

热度分
514
价值分
223
活跃状态
活跃

README

Build Status

📸 Android Camera2 Secret Picture Taker (AC2SPT)

Take pictures secretly (without preview or launching device’s camera app) from all available cameras using Android CAMERA2 API. The Camera2 API replaces the deprecated Camera class.


How can I support this project?

  • If you have enjoyed the project and it helped you creating a project, building an app, starting a business. You could encourage and support me on patreon https://www.patreon.com/hzitoun 🤗 !
  • Star this GitHub repo :star:
  • Create pull requests, submit bugs, suggest new features or documentation updates :wrench:

Usage

  1. Implement the interface PictureCapturingListener (your capture listener) and override the following methods:
    • void onDoneCapturingAllPhotos(TreeMap<String, byte[]> picturesTaken) which is called when we’ve done taking pictures from ALL available cameras OR when NO camera was detected on the device;
    • void onCaptureDone(String pictureUrl, byte[] pictureData) to get a couple (picture Url, picture Data). Use this method if you don’t want to wait for ALL pictures to be ready;
  2. Create a new instance of APictureCapturingService using PictureCapturingServiceImpl#getInstance() method;
  3. Start capture by calling the method APictureCapturingService#startCapturing(PictureCapturingListener listener) and pass the listener you’ve just implemented (step 1)

Sample

Here, I’ve chosen to just display the two pictures taken within a vertical linear layout. Here is a code snippet of how to use the service:

public class MainActivity extends AppCompatActivity implements PictureCapturingListener, ActivityCompat.OnRequestPermissionsResultCallback {
     private APictureCapturingService pictureService;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //check for camera and external storage permissions
        checkPermissions();
        final Button btn = (Button) findViewById(R.id.startCaptureBtn);
        pictureService = PictureCapturingServiceImpl.getInstance(this);
        //start capturing when clicking on the button
        btn.setOnClickListener(v ->
                pictureService.startCapturing(this)
        );
    }

    @Override
    public void onDoneCapturingAllPhotos(TreeMap<String, byte[]> picturesTaken) {
        if (picturesTaken != null && !picturesTaken.isEmpty()) {
            picturesTaken.forEach((pictureUrl, pictureData) -> {
               //convert the byte array 'pictureData' to a bitmap (no need to read the file from the external storage) but in case you
               //You can also use 'pictureUrl' which stores the picture's location on the device
                final Bitmap bitmap = BitmapFactory.decodeByteArray(pictureData, 0, pictureData.length);
            });
            showToast("Done capturing all photos!");
            return;
        }
        showToast("No camera detected!");
    }

    @Override
    public void onCaptureDone(String pictureUrl, byte[] pictureData) {
        if (pictureData != null && pictureUrl != null) {
            runOnUiThread(() -> {
                //convert byte array 'pictureData' to a bitmap (no need to read the file from the external storage)
                final Bitmap bitmap = BitmapFactory.decodeByteArray(pictureData, 0, pictureData.length);
                //scale image to avoid POTENTIAL "Bitmap too large to be uploaded into a texture" when displaying into an ImageView
                final int nh = (int) (bitmap.getHeight() * (512.0 / bitmap.getWidth()));
                final Bitmap scaled = Bitmap.createScaledBitmap(bitmap, 512, nh, true);
               //do whatever you want with the bitmap or the scaled one...
            });
            showToast("Picture saved to " + pictureUrl);
        }
    }
    
    private void showToast(final String text) {
        runOnUiThread(() ->
                Toast.makeText(getApplicationContext(), text, Toast.LENGTH_SHORT).show()
        );
    }

}

Thanks to maaudrana for the logo :)

Contributors

Hamed ZITOUN [email protected]

Help

If you run into issues, please don’t hesitate to find help on the GitHub project.

License

The android-camera2-secret-picture-taker is covered by the MIT License.

The MIT License (MIT)

Copyright © 2022 Hamed ZITOUN and contributors to the android-camera2-secret-picture-taker project.

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.

评论

暂无评论