creating buffered image
hi,
I am working on an image processing application and thought of
creating a class called FaceImage to represent a n image of a human
face.I created the class like this
public class FaceImage {
private String fileName;
private int width;
private int height;
double[] data;
public FaceImage(File imageFile) throws MyException{
if (isAnImageFile(imageFile.getPath())){
try{
BufferedImage b=ImageIO.read(imageFile);
b=convertToGray(b);
int w=b.getWidth();
int h=b.getHeight();
this.height=h;
this.width=w;
this.data=new double[h*w];
b.getData().getPixels(0,0, w,h,data);
}catch(IOException e){
e.printStackTrace();
}
}else{
throw new MyException("file"+imageFile.getPath()+" is not an image
file");
}
}
public FaceImage(String imageName,int width,int height,double[]
data) throws MyException{
if (data.length !=width*height){
throw new MyException("data size must be equal to "+width*height);
}
this.fileName=imageName;
this.width=width;
this.height=height;
this.data=data;
}
...
public boolean isAnImageFile(String fileName){
//check if an image and return true or false
.....
}
}
I also wanted to implement a saveImage() method so that I can save the
FaceImage object as an image file of given format.However when I tried
MemoryImageSource constructor I found that it needs an int[] not
double[].
Is there some way I can use the double[] containing pixel to save a
new image?do I need to convert the double[] to int[] as needed by
MemoryImageSource ?I guess a for loop would be very inefficient.
Any help or advice would be nice.
thanks