user1993381
user1993381

Reputation: 179

generating a new image using a transformer class java

I am using a transformer class in order to generate a new image with modified pixels. Basically I am iterating over each pixel in the original image, then applying the given transformation (ex. color inversion, contrast, etc.) in order to generate a new picture. I'm not really sure how to approach this problem...this is what I have so far.

public static NewPicture transform(NewPicture p, Transformer t) {
int w = p.getWidth();
int h = p.getHeight();

Pixel[][] src = getBitmap();
Pixel[][] tgt = new Pixel[w][h];

for (int x = 0; x < w; x++) {
  for (int y = 0; y < h; y++) {
    // Not sure what to do after this nested for loop

NewPicture is simply an image represented by a 2D array of Pixels. The interface for my Pixel transformer is

public interface Transformer {
  public Pixel transformPixel (pixel p);
}

It simply creates a new Pixel based on the given RGB components of the input, but does not modify the pixel.

I would appreciate any guidance as to how to approach this problem. Thanks.

Upvotes: 0

Views: 89

Answers (1)

Mordechai
Mordechai

Reputation: 16234

Take a look at the RGBImageFilter class, that does exactly what you want.

Upvotes: 1

Related Questions