How do i make the .bmp image to be black/white ?
I have this small program
Code :
package fisiere;
import java.io.*;
import java.util.Scanner;
public class Fisieremain {
public static void main(String[] args) {
int B;
int G;
int R;
try
{
BufferedInputStream fisier = new BufferedInputStream(new FileInputStream("pisica.bmp")); //file i read bytes from
BufferedOutputStream fisier2 = new BufferedOutputStream (new FileOutputStream("C:/Users/npiulitza/Desktop/poza/poze2094.bmp")); // here i write them
for (int i =0; i<54; i++)
{
fisier2.write(fisier.read()); // here i copy the header of the file
}
while (true)
{
B = fisier.read(); // here i read values for each of the three colors
G = fisier.read();
R = fisier.read();
fisier2.write(B); // and here i write them to second file
if (B==-1)
break; // the bubble ends when there are no more bytes to read
fisier2.write(G);
fisier2.write(R);
}
fisier.close();
fisier2.close();
}
catch (IOException e)
{
System.out.println(e);
}
}
}
In this program, i read from a .bmp files the blue, yellow and read color values for each pixel of the image. And, after write them as bytes to another .bmp file. It works, i could even manage to change colors little, if i make blue and yellow to be 0, the image will be red, but i wonder if there is any formula for obtaining a black/white image. Searched little on google but did not find something to help :(
Re: How do i make the .bmp image to be black/white ?
Are you looking for an algorithm for converting pixels to either black or white?
Read a pixel and change its color to either 0x000000 or 0xFFFFFF
Re: How do i make the .bmp image to be black/white ?
No, i do not need to use HTML colors. In my code, B is blue value (from 0 to 256) , G is yellow and R is red. And there where i write them to the file
Quote:
fisier2.write(B); // and here i write them to second file
if (B==-1)
break; // the bubble ends when there are no more bytes to read
fisier2.write(G);
fisier2.write(R);
i need to sum or make an operation with these values. For example if i decrease each of them like this
Quote:
fisier2.write(B-100); // and here i write them to second file
if (B==-1)
break; // the bubble ends when there are no more bytes to read
fisier2.write(G-100);
fisier2.write(R-100);
My picture will have negative colors. And i remember i heard some time ago it is a formula to make it black/white ( i think 2 of them need to be 0 for each pixel and one should have all the colors added or decreased or something)
Re: How do i make the .bmp image to be black/white ?
Sorry, i have not ideas about the algorithms you mention.
If you only want black and white then you need to write either 0, 0, 0 or FF FF FF for the three bytes.
Re: How do i make the .bmp image to be black/white ?
No, i do not want like that, i want the picture become as if it was taken with black/white camera, not that some pixels be pure black and others pure white, it should also have gray pixels. Well, i will search little more and will try discover the formula myself:). And i am sure i have to mix somehow blue,red and yellow color intensities.
Re: How do i make the .bmp image to be black/white ?
Quote:
it should also have gray pixels
Quote:
How do i make the .bmp image to be black/white ?
There is s contradiction here. B/W vs gray.
2 Attachment(s)
Re: How do i make the .bmp image to be black/white ?
Hmm look mate, i have writen for every color
Quote:
fisier2.write(B/2);
fisier2.write(B/2);
fisier2.write(B/2);
And the picture that was
Attachment 685
And, after it is
Attachment 686
And...you do not say the second picture in black/white ?
Re: How do i make the .bmp image to be black/white ?
I don't see any white in the second picture.