Carved Effect Bitmap - Android Graphics

Android examples for Graphics:Bitmap Effect

Description

Carved Effect Bitmap

Demo Code


//package com.java2s;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Paint;

public class Main {

    public static Bitmap fudiaoEffect(Bitmap bitmap) {
        int width = bitmap.getWidth();
        int height = bitmap.getHeight();
        Bitmap base = Bitmap/*  ww  w  .  ja  va  2 s.  co m*/
                .createBitmap(width, height, bitmap.getConfig());

        Canvas canvas = new Canvas(base);
        canvas.drawBitmap(bitmap, new Matrix(), new Paint());

        int pre_color = 0;
        for (int i = 0; i < width; i++)//
        {
            for (int j = 0; j < height; j++) {
                int current_color = bitmap.getPixel(i, j);

                int r = Color.red(current_color) - Color.red(pre_color)
                        + 128;
                int g = Color.green(current_color) - Color.green(pre_color)
                        + 128;
                int b = Color.blue(current_color) - Color.blue(pre_color)
                        + 128;
                int a = Color.alpha(current_color);

                int newcolor = (int) (r * 0.3 + g * 0.59 + b * 0.11);//

                base.setPixel(i, j,
                        Color.argb(a, newcolor, newcolor, newcolor));
                pre_color = current_color;
            }
        }
        return base;
    }
}

Related Tutorials