Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MatrixToImageWriter(int ARGOncolor,int ARGOffcolor) not changing colour of the barcode #1397

Closed
DarkMortal opened this issue Jun 13, 2021 · 8 comments

Comments

@DarkMortal
Copy link

DarkMortal commented Jun 13, 2021

Bug Reports

I was using this function to create a colorful barcode but the output was plain black& white barcode.

This is the part where I used a function I created RGB which takes 2 integers (red,green,blue values) as parameter & returns an ARGB int value to work with.
The code was working till last night but I don't know for some reason it's not working now.

BitMatrix matrix = writer.encode(text, BarcodeFormat.CODE_128, 500, 300);
MatrixToImageConfig conf = new MatrixToImageConfig(RGB(0,0,255),RGB(0,255,0));
BufferedImage qrcode = MatrixToImageWriter.toBufferedImage(matrix, conf);
File outputfile = new File(path);
ImageIO.write(qrcode, "png", outputfile);

Here's the declaration of the RGB function:-
private static int RGB(int red,int green,int blue) {
int rgb=(65536*red+256*green+blue);
return ((16777215-rgb)*(-1));
}

Here's the resultant barcode128 image
New2

And here's the console output:-
On Color = -16776960
Off Color = -16711935

@DarkMortal
Copy link
Author

Please check the second answer of this question on stack overflow

@srowen
Copy link
Contributor

srowen commented Jun 13, 2021

That function doesn't seem to produce the correct ints - not sure what the logic of the return statement is but rgb is already correct here. Try it out and see that it doesn't give the right answer. Honestly it's easier to just write hex constants instead of that function -- 0x0000FF, 0x00FF00

@srowen srowen closed this as completed Jun 13, 2021
@DarkMortal
Copy link
Author

DarkMortal commented Jun 13, 2021

I tried your suggestion, still getting that same black & white 128 barcode. I changed the dimensions of the BitMatrix but still the same result

@srowen
Copy link
Contributor

srowen commented Jun 13, 2021

Hm, I think you don't want transparency, so you need to ensure the top byte is 0xFF, as in 0xFF00FF00 for example.

@DarkMortal
Copy link
Author

I tried your solution and the issue still remains
Here's my barcode again:-
New232

I tried every possible solution I found but still no good

@DarkMortal
Copy link
Author

Hm, I think you don't want transparency, so you need to ensure the top byte is 0xFF, as in 0xFF00FF00 for example.

Even if I pass 0xFFFFFFFF as both onColor and offColor, still I get the standard black & white barcode, whereas I should get a blank white image

@srowen
Copy link
Contributor

srowen commented Jun 13, 2021

Works fine for me. Are you sure you're reading the right path? Ex:

    Code128Writer writer = new Code128Writer();
    BitMatrix matrix = writer.encode("foobar", BarcodeFormat.CODE_128, 500, 300);
    MatrixToImageConfig conf = new MatrixToImageConfig(0xFF00FF00, 0xFF0000FF);
    BufferedImage qrcode = MatrixToImageWriter.toBufferedImage(matrix, conf);
    File outputfile = new File("/tmp/out.png");
    ImageIO.write(qrcode, "png", outputfile);

out

@DarkMortal
Copy link
Author

It's working now. Thanks a lot man. You're a lifesaver

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants