I want to write a utility which converts org.bytedeco.javacpp.lept.PIX
to byte[]
and BufferedImage
. I have tried the following:
1) using Java2DFrameUtils but it inverts my image colors ( 1-> 0 and 0-> 1) with the code:
LeptonicaFrameConverter c = new LeptonicaFrameConverter();
Frame f = c.convert(src);
BufferedImage img = Java2DFrameUtils.toBufferedImage(f);
2) this approach does not use the org.bytedeco.javacpp
package, so it does not help me.
3) When I try to use PointerPointer
and SizeTPointer
of this package, I get error saying
"Error in pixWriteMem: &data not defined".
Here is my code:
PointerPointer pp = new PointerPointer();
SizeTPointer psize = new SizeTPointer();
lept.pixWriteMem(pp, psize, src, lept.IFF_TIFF);
byte[] by = pp.asByteBuffer().array();
BufferedImage img = ImageIO.read(new ByteArrayInputStream(by));
Any help would be appreciated. TIA.