Code Monkey home page Code Monkey logo

simple_camera's Introduction

Simple Camera

simple camera package

It is a package for using the camera in a simple and fast way.

Features

  • Display live camera preview in a widget.
  • Access the image and video stream.
  • Enable or disable Audio.
  • Change resolution image.
  • Change format image.
  • Change flash mode.
  • Change exposure mode.
  • Change focus mode.

Installation and usage

Add the package to your dependencies

dependencies:
  simple_camera: ^1.0.3
  ...

Plataform specific setup

  • iOS

Add two rows to the ios/Runner/Info.plist:

  • one with the key Privacy - Camera Usage Description and a usage description.
  • and one with the key Privacy - Microphone Usage Description and a usage description.

If editing Info.plist as text, add:

<key>NSCameraUsageDescription</key>
<string>your usage description here</string>
<key>NSMicrophoneUsageDescription</key>
<string>your usage description here</string>
  • Android

Change the minimum SDK version to 21 (or higher) in android/app/build.gradle:

minSdkVersion 21

If you want to record videos with audio, add this permission to your AndroidManifest.xml:

Getting started

To begin with, it's very simple, just import and instantiate SimpleCamera and then initialize it according to the example, after that you can use SimpleCameraPreview or create your own screen by calling simpleCamera.buildPreview()

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  var simpleCamera = SimpleCamera();

  @override
  void initState() {
    super.initState();
    initSimpleCamera();
  }

  @override
  void dispose() {
    super.dispose();
    simpleCamera.dispose();
  }

  void initSimpleCamera() async {
    try {
      // Here you initialize the camera and pass some options, such as resolution, image format, etc..
      // If it does not inform any camera description, by default it starts with the front camera
      // To learn more, see the documentation.
      simpleCamera.initializeCamera().then((value) {
        setState(() {});
      });
    } catch (e) {
      // Important
      // Here you must give the permissions to access the device camera and or audio
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SimpleCameraPreview(
        simpleCamera: simpleCamera,
        isFull: true,
        onPressedGallery: () {},
        onPressedVideoRecording: (xfile) {
          if (kDebugMode) {
            print(xfile?.name);
          }
        },
        onPressedTakePicture: (xfile) {
          if (kDebugMode) {
            print(xfile?.name);
          }
        },
      ),
    );
  }
}

References and description

Here are all the references you can use and what each one does

Name Return Description
availableCameras List returns all available cameras on the device
initializeCamera void initialize the camera
switchCamera void switch between back and front camera
switchFlash void switch between flash modes
startVideoStream Stream starts a stream of images from the video
stopVideoStream void close the video stream
startVideoRecording void starts recording a video
stopVideoRecording Future finishes recording and returns the file
startImageStream Stream returns an image stream
setFlashMode void change flash mode
setExposureMode void change the exposure mode
setFocusMode void change focus mode
buildPreview Widget returns a widget for the camera view
dispose void discard the camera
----------------------- --------------------------------- -----------------------------------------------------------------------

simple_camera's People

Contributors

mathlouly avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.