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 aView
without needed to displaying it. - Export or generate
Image File
from aView
without needed to displaying it. - Configurable bitmap and image file generator.
- With
View
extension function forKotlin
user. - Friendly method for
Java
user too.
dependencies {
implementation 'id.zelory:cekrek:1.0.0'
}
val bitmap = Cekrek.toBitmap(view)
// 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
}
val bitmap = view.cekrekToBitmap()
// 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
}
val config = CekrekConfig().apply {
canvasConfig.width = CanvasSize.Specific(1280)
}
val bitmap = Cekrek.toBitmap(view, config)
// or
val bitmap = view.cekrekToBitmap(config)
val imageFile = Cekrek.toImageFile(view, destination)
// 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
}
val imageFile = view.cekrekToImageFile(destination)
// 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
}
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)
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.