How to create a Raster from a float float array in Java?

I am trying to use BufferedImage, apply Fourier transform (using jtransforms) and write data back to BufferedImage. But I’m stuck in creating a new raster to get the results back; I don’t see something here?

BufferedImage bitmap;
float [] bitfloat = null;

bitmap = ImageIO.read(new File("filename"));
FloatDCT_2D dct = new FloatDCT_2D(bitmap.getWidth(),bitmap.getHeight());

bitfloat = bitmap.getData().getPixels(0, 0, bitmap.getWidth(), bitmap.getHeight(), bitfloat);
dct.forward(bitfloat, false);

But I'm at a dead end trying to end this line, what should I give the createRaster function? Javadocs for createRaster doesn't make any sense to me:

bitmap.setData(Raster.createRaster(`arg1`, `arg2`, `arg3`));

I'm starting to wonder if a float array is needed, but there are not many jtransform examples there.

+3
source share
2 answers

Do not create a new one Raster. Use WritableRaster.setPixels(int,int,int,int,float[])to write an array back to the image.

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

final WritableRaster wr = bitmap.getData();
bitfloat = wr.getPixels(0, 0, w, h, bitfloat);

// do processing here

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

, , ; ImageIO .

+4

Google FloatDCT_2D, , / , , , "edu.emory.mathcs.jtransforms.dct.FloatDCT_2D". , , , .

, , , .

... Raster.createRaster() , - , , . ??? .

0

Source: https://habr.com/ru/post/1771373/


All Articles