I have this small program
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