Skip to content

stedi-akk/RandomImageGenerator

Repository files navigation

RIG – Random Image Generator

A library for Android that generates random Bitmap images. Generation is performed on the basis of different passed parameters like width, height, type of generator, color palette, etc. Images can be also automatically saved in the requested path with appropriate quality.

Usage

Simple example with callback:

new Rig.Builder()
        .setGenerator(generator)
        .setFixedSize(1920, 1080) // can be also 1x1, 1x1000, etc
        .setCount(10)
        .setCallback(new GenerateCallback() {
            @Override
            public void onGenerated(ImageParams imageParams, Bitmap bitmap) {
                // will be called 10 times with a new bitmap 1920x1080 on every call
            }
            @Override
            public void onFailedToGenerate(ImageParams imageParams, Exception e) {
                // in case if generation failed
            }
        })
        .build()
        .generate();

Simple example with compression:

new Rig.Builder()
        .setGenerator(generator)
        .setFixedSize(1920, 1080) // can be also 666x666, 1337x1337, etc
        .setQuality(Quality.jpg(90))
        .setFileSavePath(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).getPath())
        .setFileSaveCallback(new SaveCallback() {
            @Override
            public void onSaved(Bitmap bitmap, File file) {
                // will be called when bitmap is saved
            }
            @Override
            public void onFailedToSave(Bitmap bitmap, Exception e) {
                // in case if compression failed
            }
        })
        .build()
        .generate();

For more information, please see Rig.Builder javadoc.

Embed generators

There are currently 6 generators, and 3 effects.

Custom generators

To create your own generator, you just need to implement Generator interface:

public class MyGenerator implements Generator {
    @Override
    public Bitmap generate(ImageParams imageParams) throws Exception {
        // your generation here
    }
}

Color palette

By default, the library generates images with all available HSV colors. RigPalette class is used to change this palette.

Examples:

RigPalette.blackAndWhite()

RigPalette.fromColor(Color.RED)

RigPalette.fromColor(Color.GREEN)

RigPalette.fromColor(Color.BLUE)

Download

Gradle:

compile 'com.stedi.randomimagegenerator:rig:1.1.0'

There is also a sample application available in the /sample directory.

License

Copyright 2018 Dima Stepanchenko

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.