Markovian8261
Markovian8261

Reputation: 899

Convert int array into bufferedImage in java

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.

Upvotes: 2

Views: 1554

Answers (1)

Flack Ninja
Flack Ninja

Reputation: 63

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); 

Upvotes: 2

Related Questions