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.

1
  • is there no setRaster()-method? Commented Dec 29, 2012 at 17:32

1 Answer 1

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); 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.