I use a java program to resize my jpg's for imgsrc settings and speed on mobile, etc.
I am using ImageIO and BufferedImage
The file types are TYPE_3BYTE_BRG, and written out that was also that type as a smaller, sans metadata, jpg.
This is the resizing code:
BufferedImage resizedImage = new BufferedImage(width, newHeight, type);
Graphics2D g = resizedImage.createGraphics();
g.drawImage(originalImage, 0, 0, width, newHeight, null);
g.dispose();
g.setComposite(AlphaComposite.Src);
g.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_BILINEAR);
g.setRenderingHint(RenderingHints.KEY_RENDERING,
RenderingHints.VALUE_RENDER_QUALITY);
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
The saving code (this calls the above)
BufferedImage originalImage = ImageIO.read(new
File(fileEntry.getParent()+"/"+s));
int type = originalImage.getType() == 0? BufferedImage.TYPE_INT_RGB : originalImage.getType();
System.out.println("Original is "+type);
f=new File(fileEntry.getParent()+"/"+strippedname+"0x.jpg");
if(!f.exists())
{
System.out.println("Create "+fileEntry.getPath()+"/"+strippedname+"0x.jpg");
BufferedImage resizeImageJpg = resizeImageWithHint(originalImage, type, 50);
ImageIO.write(resizeImageJpg, "jpg", f);
}
Facebook says the Jpg is an invalid format to be processed, and for the life of me, I can't figure out why.
I did open the "offending" jpg for the ogimage in Photoshop, and saved it from there, which still gave an error from FB, but at least it showed on the preview at that point. FYI until a few months ago, this wasn't an issue.
Any ideas here?
g.dispose()
before you've finished?