Javacv: Java2DFrameConverter.cloneBufferedImage makes images black

Created on 4 Jul 2017  路  14Comments  路  Source: bytedeco/javacv

What for is this condition "type == BufferedImage.TYPE_CUSTOM" used in the method Java2DFrameConverter.cloneBufferedImage?
https://github.com/bytedeco/javacv/blob/master/src/main/java/org/bytedeco/javacv/Java2DFrameConverter.java#L75
It makes all my images black. Without this condition all work fine.

bug

All 14 comments

It just tries to create a BufferedImage of the same type, but in the case of TYPE_CUSTOM, we probably need to do more work to support all kinds of formats...

It returns new BufferedImage with the same type but without data.
If I use this:

Java2DFrameConverter converter = new Java2DFrameConverter();
Java2DFrameConverter.cloneBufferedImage(converter.convert(frame));

it returns:

return new BufferedImage(bi.getWidth(), bi.getHeight(), type);

Maybe it's better to mark this condition with @todo (or just comment it) and to put only this code in the method?

return new BufferedImage(bi.getColorModel(), bi.copyData(null), bi.isAlphaPremultiplied(), null);

Well, that won't return an image of the right type. So let's get this fixed properly.

We could adopt this solution: https://stackoverflow.com/a/19327237/523744

Could you check that it works in your case? And please do send a PR! Thanks

Isn't it the same as my code above? Are you talking about this one:

static BufferedImage deepCopy(BufferedImage bi) {
    ColorModel cm = bi.getColorModel();
    boolean isAlphaPremultiplied = cm.isAlphaPremultiplied();
    WritableRaster raster = bi.copyData(null);
    return new BufferedImage(cm, raster, isAlphaPremultiplied, null);
}

I just replaced this:

ColorModel cm = bi.getColorModel();
boolean isAlphaPremultiplied = cm.isAlphaPremultiplied();

with this:

bi.isAlphaPremultiplied();

And both of them work properly.

No, the one under, this one: https://stackoverflow.com/a/19327237/523744

Ok. I'll test it.

Right, that's the same thing though. It doesn't copy the imageType when it's not equal to TYPE_CUSTOM.

Now what's the plan? Do I have to create PRs for both of this files or for the Java2DFrameConverter only?

Java2DFrameUtils should be using Java2DFrameConverter, so let's do that. Sounds good?

Yes. I was going to do it the same way.

Released in version 1.3.3. Thanks for your contribution!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

chrisliu12345 picture chrisliu12345  路  4Comments

cansik picture cansik  路  4Comments

Bahramudin picture Bahramudin  路  3Comments

RaGreen picture RaGreen  路  4Comments

newstarbka picture newstarbka  路  5Comments