Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import android.graphics.Bitmap;

import android.graphics.Color;

import android.widget.ImageView;

public class Main {
    static public void setImageColorPixels(ImageView view, Bitmap myBitmap, int rgbcolor)// ,Bitmap sourceBitmap)
    {

        int intArray[];

        intArray = new int[myBitmap.getWidth() * myBitmap.getHeight()];

        // copy pixel data from the Bitmap into the 'intArray' array
        myBitmap.getPixels(intArray, 0, myBitmap.getHeight(), 0, 0, myBitmap.getHeight(), myBitmap.getWidth());

        // replace the red pixels with yellow ones
        for (int i = 0; i < intArray.length; i++) {
            // System.out.println("color is--" + i + " " + intArray[i]);
            if (intArray[i] != Color.TRANSPARENT) {

                intArray[i] = rgbcolor;
            }
        }
        myBitmap.setPixels(intArray, 0, myBitmap.getHeight(), 0, 0, myBitmap.getHeight(), myBitmap.getWidth());

        view.setImageBitmap(myBitmap);
    }
}