RGB to Grayscale, bmp image in java
My teacher gave us a task to make a class that takes an 640x480 bmp
colored image, to convert it in grayscale image, I found some sources with
ideas so i did it. But there's a problem because it seems that it makes it
cause it doesn't give me error, but the output doesn't appear. I think
it's my code. My code is
import java.io.*;
public class Grayscale{
FileInputStream image;
FileOutputStream img;
byte[] datos;
int gray;
public Grayscale(String nombre)throws Exception{
this.image = new FileInputStream(nombre);
this.img = img;
this.datos = new byte[image.available()];
this.gray = gray;
}
public void gray()throws Exception{
image.read(datos);
img = new FileOutputStream("grayscaleprueba.bmp");
for (int i = 0; i<datos.length; i++){
gray = (byte)(datos[i]*0.3 + datos[i+1]*0.59 + datos[i+2]);
datos[i] = (byte)gray;
datos[i+1] = (byte)gray;
datos[i+2] = (byte)gray;
}
img.write(datos);
}
}
No comments:
Post a Comment