handle Relief Image Effect - Android Graphics

Android examples for Graphics:Bitmap Effect

Description

handle Relief Image Effect

Demo Code


//package com.java2s;
import android.graphics.Bitmap;

import android.graphics.Color;

public class Main {

    public static Bitmap handleReliefImgEffect(Bitmap bitmap) {
        int width = bitmap.getWidth();
        int height = bitmap.getHeight();

        int oldPix[] = new int[width * height];
        int newPix[] = new int[width * height];

        Bitmap bmp = Bitmap.createBitmap(width, height,
                Bitmap.Config.ARGB_8888);

        bitmap.getPixels(oldPix, 0, width, 0, 0, width, height);

        for (int i = 1; i < width * height; i++) {
            int a, r, g, b;
            r = Color.red(oldPix[i]);
            g = Color.green(oldPix[i]);
            b = Color.blue(oldPix[i]);
            a = Color.alpha(oldPix[i]);

            int a1 = Color.alpha(oldPix[i - 1]);
            int r1 = Color.red(oldPix[i - 1]);
            int g1 = Color.green(oldPix[i - 1]);
            int b1 = Color.blue(oldPix[i - 1]);

            r = r1 - r + 127;//from  ww  w .j a va2 s.  c o  m
            g = g1 - g + 127;
            b = b1 - b + 127;

            if (r > 255) {
                r = 255;
            } else if (r < 0) {
                r = 0;
            }

            if (g > 255) {
                g = 255;
            } else if (g < 0) {
                g = 0;
            }

            if (b > 255) {
                b = 255;
            } else if (b < 0) {
                b = 0;
            }

            newPix[i] = Color.argb(a1, r, g, b);
        }
        bmp.setPixels(newPix, 0, width, 0, 0, width, height);

        return bmp;
    }
}

Related Tutorials