Giter VIP home page Giter VIP logo

cekrek's Introduction

Cekrek

Android Arsenal Build Status codecov Code Climate

Cekrek is an android library that allows you to export any view to bitmap or image file in a convenient way.

  • Export or generate Bitmap from a View without needed to displaying it.
  • Export or generate Image File from a View without needed to displaying it.
  • Configurable bitmap and image file generator.
  • With View extension function for Kotlin user.
  • Friendly method for Java user too.

Gradle

dependencies {
    implementation 'id.zelory:cekrek:1.0.0'
}

Export a view to bitmap

Export to bitmap

val bitmap = Cekrek.toBitmap(view)

Export to bitmap with configuration

// export view to 1280 x 1280 canvas with red background color.
val bitmap = Cekrek.toBitmap(view) {
    canvasConfig.width = CanvasSize.Specific(1280) // set canvas size to 1280 px
    canvasConfig.height = CanvasSize.Specific(1280) // default is CanvasSize.WrapContent
    canvasConfig.color = Color.RED // default is Color.WHITE
}

Export to bitmap with extension function

val bitmap = view.cekrekToBitmap()

Export to bitmap with extension function + configuration

// export view to 1280 x 1280 canvas with red background color.
val bitmap = view.cekrekToBitmap {
    canvasConfig.width = CanvasSize.Specific(1280) // set canvas size to 1280 px
    canvasConfig.height = CanvasSize.Specific(1280) // default is CanvasSize.WrapContent
    canvasConfig.color = Color.RED // default is Color.WHITE
}

Export to bitmap with config variable

val config = CekrekConfig().apply {
    canvasConfig.width = CanvasSize.Specific(1280)
}
val bitmap = Cekrek.toBitmap(view, config)
// or
val bitmap = view.cekrekToBitmap(config)

Export a view to image file

Export to image file

val imageFile = Cekrek.toImageFile(view, destination)

Export to image file with configuration

// export view to 1280 x 1280 canvas with red background color and save it as PNG file.
val imageFile = Cekrek.toImageFile(view, destination) {
    cekrekConfig.canvasConfig.width = CanvasSize.Specific(1280) // set canvas size to 1280 px
    cekrekConfig.canvasConfig.height = CanvasSize.Specific(1280) // default is CanvasSize.WrapContent
    cekrekConfig.canvasConfig.color = Color.RED // default is Color.WHITE
    format = Bitmap.CompressFormat.PNG
}

Export to image file with extension function

val imageFile = view.cekrekToImageFile(destination)

Export to image file with extension function + configuration

// export view to 1280 x 1280 canvas with red background color and save it as PNG file.
val imageFile = view.cekrekToImageFile(destination) {
    cekrekConfig.canvasConfig.width = CanvasSize.Specific(1280) // set canvas size to 1280 px
    cekrekConfig.canvasConfig.height = CanvasSize.Specific(1280) // default is CanvasSize.WrapContent
    cekrekConfig.canvasConfig.color = Color.RED // default is Color.WHITE
    format = Bitmap.CompressFormat.PNG
}

Export to image file with config variable

val config = CekrekImageFileConfig(destination).apply {
    cekrekConfig.canvasConfig.width = CanvasSize.Specific(1280)
    format = Bitmap.CompressFormat.PNG
}
val imageFile = Cekrek.toImageFile(view, config)
// or
val imageFile = view.cekrekToImageFile(config)

License

Copyright (c) 2020 Zetra.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

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.