/Chafu

A photo browser and camera library for Xamarin.iOS

Primary LanguageC#MIT LicenseMIT

Chafu

Continuous Integration

Build Server Platform Build Status
AppVeyor Windows AppVeyor Build status
Bitrise macOS Bitrise
VSTS Windows Visual Studio Team services
MyGet Windows chafu MyGet Build Status

Packages

NuGet

Description

Chafu is a photo browser and camera library for Xamarin.iOS. It is heavily inspired from Fusuma, which is a Swift library written by ytakzk.

It has been tweaked for ease of use in a C# environment, all xibs converted to C# code and unnecessary wrapper views have been removed. The library has been simplified and loads of unfixed Fusuma bugs and features have been fixed in this library.

Preview

Features

  • UIImagePickerController alternative
  • Camera roll (images and video)
  • Album view to show images and video from folder
  • Camera for capturing both photos and video
  • Cropping of photos into squares
  • Toggling of flash when capturing photos and video
  • Supports front and back cameras
  • Face detection
  • Customizable

Installation

Install from NuGet

Install-Package Chafu

Note: iOS 10 requires the developer to provide usage descriptions in the info.plist. Otherwise, the application will crash, when requesting permissions to camera, photo library or microphone.

<key>NSPhotoLibraryUsageDescription</key>
<string>Describe what photo library is used for</string>
<key>NSCameraUsageDescription</key>
<string>Describe what camera is used for</string>
<key>NSMicrophoneUsageDescription</key>
<string>Describe what microphone is used for</string>

Usage

Add a using chafu; in the top of your class.

var chafu = new ChafuViewController();
chafu.HasVideo = true; // add video tab
chafu.MediaTypes = MediaType.Image | MediaType.Video // customize what to show
PresentViewController(chafu, true);

or if you only want to show gallery:

var gallery = new AlbumViewController();
gallery.MediaTypes = MediaType.Image | MediaType.Video // customize what to show
PresentViewController(gallery, true);

Both accept custom data source which will be instantiated lazily:

var chafu = new AlbumViewController {
    LazyDataSource = (view, size, mediaTypes) => 
        new LocalFilesDataSource(view, size, mediaTypes) {ImagesPath = path},
    LazyDelegate = (view, source) => new LocalFilesDelegate(view, (LocalFilesDataSource) source),
};

where path is a directory the App has access to.

Events

// When image is selected or captured with camera
chafu.ImageSelected += (sender, image) => imageView.Image = image;

// When video is captured with camera
chafu.VideoSelected += (sender, videoUrl) => urlLabel.Text = videoUrl.AbsoluteString;

// When ViewController is dismissed
chafu.Closed += (sender, e) => { /* do stuff on closed */ };

// When permissions to access camera roll are denied by the user
chafu.CameraRollUnauthorized += (s, e) => { /* do stuff when Camera Roll is unauthorized */ };

// when permissions to access camera are denied by the user
chafu.CameraUnauthorized += (s, e) => { /* do stuff when Camera is unauthorized */ };

Customization

All customization happens through the static Configuration class.

Configuration.BaseTintColor = UIColor.White;
Configuration.TintColor = UIColor.Red;
Configuration.BackgroundColor = UIColor.Cyan;
Configuration.CropImage = false;
Configuration.TintIcons = true;
// etc...

Explore the class for more configuration.

Thanks to

Many thanks to ytakzk for his initial Fusuma implementation, which this library started as.

What does Chafu mean?

Fusuma means bran in Japanese, Chafu in Japanese means chaff. Chaff is sometimes confused with bran.

License

Chafu is licensed under the MIT License, see the LICENSE file for more information.