Skip to content

dyvoker/shadow-utils

Repository files navigation

Shadow Utils

API

Preview

Preview screenshot

Usage (sample)

Add dependency:

dependencies {
    implementation 'com.github.dyvoker:shadow-lib:1.1'
}

Using canvas:

...
private CanvasWithShadow shadow;
...
@Override
public void draw(@NonNull Canvas canvas) {
    if (shadow != null) {
        // Draw cached image.
        shadow.draw(canvas, 0x80000000, 3, 2, 2, !shadow.isSameSize(canvas));
        return;
    }
    shadow = new CanvasWithShadow(canvas);
    Canvas tempCanvas = shadow.getCanvas();

    // Draw primitives.
    float centerX = tempCanvas.getWidth() / 2;
    float centerY = tempCanvas.getHeight() / 2;
    float radius = Math.min(centerX, centerY) - 50.0f;
    tempCanvas.drawCircle(centerX, centerY, radius, paint);
    tempCanvas.drawRect(centerX, centerY, centerX + radius, centerY + radius, paint);

    // Draw shadow.
    shadow.draw(canvas, 0x80000000, 3, 2, 2, !shadow.isSameSize(canvas));
}

Using bitmap:

Bitmap iconHeart = BitmapFactory.decodeResource(getResources(), R.drawable.ic_heart);
Bitmap iconHeartWithShadow = ShadowUtils.addShadow(iconHeart, 0x80000000, 3, 2, 2);
iconHeart.recycle();
BitmapDrawable bitmapDrawable = new BitmapDrawable(iconHeartWithShadow);
FrameLayout bitmapSample = findViewById(R.id.bitmap_sample);
bitmapSample.setBackgroundDrawable(bitmapDrawable);

About

Utils for creation a shadow on bitmap or canvas.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages