GithubHelp home page GithubHelp logo

showurl / native_filters Goto Github PK

View Code? Open in Web Editor NEW

This project forked from nikolaydymura/native_filters

0.0 1.0 0.0 47.39 MB

License: MIT License

Ruby 0.28% Objective-C 8.34% Java 20.64% Dart 61.79% Swift 4.17% HTML 0.15% GLSL 4.63%

native_filters's Introduction

Core Image and GPUImage filters package for Flutter

A flutter package for iOS and Android for applying filter to image and video. Support all filters from Core Image on iOS.

Installation

Add native_filters package as a dependency in your pubspec.yaml file.

iOS

No additional configuration required, the plugin work out of the box.

Android

No additional configuration required, the plugin work out of the box.

Example

import 'dart:io';
import 'dart:typed_data';

import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:native_filters/native_filters.dart';
import 'package:path_provider/path_provider.dart';
import 'package:uuid/uuid.dart';

void main() => runApp(new MaterialApp(home: MyApp()));

class MyApp extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  final _filtersFactory = const FilterFactory();
  Filter _filter;
  File _output;
  Uint8List _data;

  String get asset => 'images/test.jpg';

  @override
  void initState() {
    super.initState();
    _prepare().then((_) => setState(() {}));
  }

  Future<void> _prepare() async {
    final directory = await getTemporaryDirectory();
    final uuid = Uuid();
    final path = '${directory.path}/${uuid.v4()}.jpg';
    if (defaultTargetPlatform == TargetPlatform.iOS) {
      _filter = await _filtersFactory.create('CIPhotoEffectMono');
    }
    if (defaultTargetPlatform == TargetPlatform.android) {
      _filter = await _filtersFactory.create('GPUImageFalseColorFilter');
    }
    await _filter?.setAssetSource(asset);
    _output = File(path);
    await _filter?.export(_output);
    _data = await _filter?.binaryOutput;
  }

  @override
  void dispose() {
    _filtersFactory.dispose(_filter);
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(_filter?.name ?? 'Initializing...'),
      ),
      body: Center(
        child: _output == null
            ? CircularProgressIndicator()
            : Column(
                children: <Widget>[
                  Expanded(
                    child: imagePreview1,
                  ),
                  SizedBox(height: 3),
                  Expanded(
                    child: imagePreview2,
                  )
                ],
              ),
      ),
    );
  }

  Widget get imagePreview1 {
    if (_output != null) {
      return Image.file(_output);
    }
    return Text('Failed to process and save image');
  }

  Widget get imagePreview2 {
    if (_data != null) {
      return Image.memory(_data);
    }
    return Text('Failed to process image');
  }
}

Previews

alt ios result

alt android result

Plugin data types support

The following table shows how to pass values GPUImageFilter:

GPUAttributeClass Filterable method Description
float setNum
int setNum
boolean setBoolValue
PointF setPointValue
float[] setDoubleArrayValue
float[] setColorValue If name of function points on color value
PointF[] setPointArrayValue

The following table shows how to pass values CIFilter:

CIAttributeClass CIAttributeType Filterable method Description
NSNumber * setNum
NSNumber CIAttributeTypeBoolean setBoolValue
CIColor setColorValue
CIVector CIAttributeTypePosition setPointValue
CIVector CIAttributeTypeOffset setPointValue
CIVector CIAttributeTypeRectangle setPointArrayValue
CIVector CIAttributeTypePosition3 setDoubleArrayValue
CIVector setDoubleArrayValue
NSValue * setDoubleArrayValue

Getting Started

This project is a starting point for a Flutter plug-in package, a specialized package that includes platform-specific implementation code for Android and/or iOS.

For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.

native_filters's People

Contributors

nikolaydymura avatar egoreko avatar miyakeryo 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.