Negative Effect Bitmap - Android Graphics

Android examples for Graphics:Bitmap Effect

Description

Negative 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 dipianEffect(Bitmap bitmap) {
        int width = bitmap.getWidth();
        int height = bitmap.getHeight();
        //bitmap/*from  ww  w .  j  a v a 2 s .  co  m*/
        Bitmap base = Bitmap
                .createBitmap(width, height, bitmap.getConfig());
        Paint paint = new Paint();
  
        Canvas canvas = new Canvas(base);
        canvas.drawBitmap(bitmap, new Matrix(), paint);
        for (int i = 0; i < width; i++) {
            for (int j = 0; j < height; j++) {
                int color = bitmap.getPixel(i, j);
                int r = Color.red(color);
                int g = Color.green(color);
                int b = Color.blue(color);
                int a = Color.alpha(color);
          
                base.setPixel(i, j,
                        Color.argb(a, 255 - r, 255 - g, 255 - b));
            }
        }
        return base;
    }
}

Related Tutorials