aspose file tools*
The moose likes Java in General and the fly likes why do my white and black pixels come out red and grey? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "why do my white and black pixels come out red and grey?" Watch "why do my white and black pixels come out red and grey?" New topic
Author

why do my white and black pixels come out red and grey?

Ralph Cook
Ranch Hand

Joined: May 29, 2005
Posts: 479
I have the following program; it is meant to read a JPG file, create a buffered image of that file, compare each pixel to a cutoff value, and write either a black or white pixel in its place depending on whether it is above or below the cutoff.

It mostly works, except that the pixels it ends up writing appear to be either red or grey.

Clearly there's something about the pixel format I don't understand here. I'd appreciate it if someone could help me figure out what it is.

I am on a Windows system, using msPaint and Windows Picture and Fax Viewer to edit and look at the completed JPGs. I don't *think* those are affecting what I see, but then I don't understand what is happening, either.

Tina Smith
Ranch Hand

Joined: Jul 21, 2011
Posts: 177
    
    6

After replacing the >< comparisons with <, I ran it and it output a black and white image...when I saved as a PNG. Saving as a JPEG on the other hand...well let's just say that pink and turquoise aren't my favorite colors. It's a transparency problem; it can be fixed by changing this:
to this:

Yes, that's a one-character change (not including the changes to get it to compile).


Everything is theoretically impossible, until it is done. ~Robert A. Heinlein
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39869
    
  28
Tina Smith wrote:After replacing the >< comparisons with < . . .
There is a fault in the software changing < to >< inside code tags. I don’t know what it is.
Tina Smith
Ranch Hand

Joined: Jul 21, 2011
Posts: 177
    
    6

Didn't realize that, sorry.
Ralph Cook
Ranch Hand

Joined: May 29, 2005
Posts: 479
Thanks for the help -- this simple fix solved my immediate problem.

I wish I could find a mid-level tutorial on dealing with graphics at this level; it would be nice to know what the "transparency" issue actually was, instead of just removing the letter to bypass it. If someone can point me to such a beast, I'd appreciate it.

rc
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: why do my white and black pixels come out red and grey?