Reading and writing an image file in java
Last day I want to copy some images from my digital camera to another ones, i copied all the images to that cameras memory card. Both the camera is of different companies, the camera is not displaying any images that i copied, i checked the folders are the same , its not because of the folder. then i noticed the images name, one is number while other is alpha numeric name, Since i had a 1000 of images to copy, renaming one by one seems to be very difficult for me and it will take around hours to complete the renaming process. What i did is i wrote a java program that rename each picture and save to another folder. The program was successful, now the image start displaying in that camera. Here is the program........
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import javax.imageio.ImageIO;
public class RenameImageFiles {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
File f = new File("E:\\belazy");
System.out.println(f.list());
File [] list = f.listFiles();
System.out.println(list.length);
int num = 400;
for ( int i =0 ; i
String fileName = "PICT0"+num+".JPG";
System.out.println(list[i]);
BufferedImage bi = ImageIO.read(list[i]);
System.out.println(fileName+" .. "+ImageIO.write(bi, "JPG" ,new File("D:\\blazyjava\\"+fileName)));
num = num + 1;
}
}
}
No comments:
Post a Comment
Your feedback may help others !!!