MyImage.java 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. import java.io.File;
  2. import java.io.IOException;
  3. import java.awt.image.BufferedImage;
  4. import javax.imageio.ImageIO;
  5. public class MyImage{
  6. public static void main(String args[])throws IOException{
  7. int width = 963; //width of the image
  8. int height = 640; //height of the image
  9. BufferedImage image = null;
  10. File f = null;
  11. //read image
  12. try {
  13. f = new File("Images/image-processing-taj.png"); //image file path
  14. image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
  15. image = ImageIO.read(f);
  16. System.out.println("Reading complete.");
  17. } catch(IOException e){
  18. System.out.println("Error: "+e);
  19. }
  20. System.out.println("width = " + image.getWidth() + " height = " + image.getHeight());
  21. //write image
  22. try {
  23. f = new File("Images/Output.jpg"); //output file path
  24. ImageIO.write(image, "jpg", f);
  25. System.out.println("Writing complete.");
  26. } catch(IOException e){
  27. System.out.println("Error: "+e);
  28. }
  29. }//main() ends here
  30. }//class ends here