2

I was wondering how i could construct an int array in java into a buffered image. I know you can get an int array in java by doing

int[] srcpixels = ((DataBufferInt)in.getRaster().getDataBuffer()).getData();

but i dont know how to do it the other way. I need this to apply a fisheye effect to a buffered image which i found out how to do here http://popscan.blogspot.com/2012/04/fisheye-lens-equation-simple-fisheye.html but it only works with int arrays. Please help, thanks.

Markovian8261
  • 909
  • 4
  • 10
  • 23

1 Answers1

2

Use a WritableRaster:

final int w = bitmap.getWidth();
final int h = bitmap.getHeight();

final WritableRaster wr = bitmap.getData();
int []data = wr.getPixels(0, 0, w, h, data);

// do processing here

wr.setPixels(0, 0, w, h, data);