0
File tifFile = new File("C:\\Users\\msmith\\Desktop\\img2508.tif");

BufferedImage newImage = ImageIO.read(tifFile);         
    BufferedImage indexedImage = new BufferedImage(newImage.getWidth(),
            newImage.getHeight(), BufferedImage.TYPE_INT_BGR);
    Graphics2D g = indexedImage.createGraphics();
    g.drawImage(newImage, newImage.getMinX(),newImage.getMinY(),Color.WHITE, null);
    newImage=indexedImage;
ImageIO.write(newImage, "jpg", new File(imageFolder + "/" + baseName + ".jpg"));

This is my code and when I try to convert one file it complete messes up and it is only one file. I am trying to convert a file from tiff to jpg. I have tried other posts with simliar issues but no solution yet.

Original file

enter image description here

New file:

enter image description here

thats what it comes out to be. I have tried making the image file smaller in GIMP but it creates the same image just with the correct resolution. Any reason why or if I can set the color when the file is read? Also if I could set a new file size in java?

wkl
  • 77,184
  • 16
  • 165
  • 176
Mason Smith
  • 115
  • 1
  • 15
  • What happens if you do the same in Photoshop or some other converting program? – user3344003 Dec 17 '15 at 18:18
  • I have done an online one and no problem at all and also seen that post and it did not solve my problem produces same result. – Mason Smith Dec 17 '15 at 18:26
  • Also I have taken the original file, cut the size in half and saved it. Than I try to convert to jpg, same result but to PNG it is fine. Now if i try to cut the size in half while running the program than convert to PNG or jpg still causes the file to mess up. I think its something with ImageIO.read, because whenever i read the larger file it breaks. – Mason Smith Dec 17 '15 at 18:41

0 Answers0