0

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?

10
  • Why would you call g.dispose() before you've finished?
    – g00se
    Commented Mar 28 at 14:20
  • I honestly dont know, I stole the code from Google, haha. But it does write a useable JPEG by most systems. Commented Mar 28 at 14:57
  • 1
    Also you don't show how you write the image to file
    – g00se
    Commented Mar 28 at 15:00
  • 1
    Might be an idea to post an example 'bad' image too
    – g00se
    Commented Mar 28 at 16:43
  • I have absolutely no understanding how to that in a preserved format? Commented Mar 28 at 20:38

0

Browse other questions tagged or ask your own question.