Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8246835
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T22:38:22+00:00 2026-06-07T22:38:22+00:00

I am having some problem in writing bufferedimage to jpg file. in my method

  • 0

I am having some problem in writing bufferedimage to jpg file.
in my method , i am getting a bufferedimage as parameter which i need to write in a file-

here is what i am doing :

public boolean writeToFile(BufferedImage buff,String savePath) {

        try {

            System.out.println(buff.toString());
            ImageIO.write(buff, ".jpg", new File(savePath));
            return true;
        } catch (Exception e) {
            e.printStackTrace();
        } 
   }

here is what gets printed by buff.toString() :

BufferedImage@8046f4: type = 1 DirectColorModel: rmask=ff0000 gmask=ff00 bmask=ff amask=0 IntegerInterleavedRaster: width = 1024 height = 172 #Bands = 3 xOff = 0 yOff = 0 dataOffset[0] 0

program runs fine without any exception, but the generated jpg file size is 0 bytes

i tried writing image without using ImageIO :

public boolean writeToFile(BufferedImage buff,String savePath) {



        try {

            System.out.println("got image : " + buff.toString());
            Iterator iter = ImageIO.getImageWritersByFormatName("jpeg");
            ImageWriter writer = (ImageWriter)iter.next();
            ImageWriteParam iwp = writer.getDefaultWriteParam();


            iwp.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
            iwp.setCompressionQuality(.5f); 


            File file = new File(savePath);
            FileImageOutputStream output = new FileImageOutputStream(file);
            writer.setOutput(output);
            IIOImage image = new IIOImage(buff, null, null);
            writer.write(null, image, iwp);
            writer.dispose();

            return true;
        } catch (Exception e) {
             e.printStackTrace();
        }

        return false;
    }

And this works absolutely fine.

Why it is not working with ImageIO ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T22:38:23+00:00Added an answer on June 7, 2026 at 10:38 pm

    Remove the . from your format name.

    ImageIO.write(buff, "jpg", new File(savePath));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having some problem writing a tab delimited string into a txt file. //This
I am having some problems writing to a file in unicode inside my c
I am having some problems with writing a CSV file. The program, I made
OK, I'm having some trouble writing multiple lines to a text file. the program
Hi I'm having some problem with a PHP page: I'm writing a little CMS
I'm having some trouble with a generic method I'm writing. It has the following
I am writing a program in Qt c++ and I'm having some problem handling
I'm having a problem writing Norwegian characters into an XML file using C#. I
Im currently writing some form validation with jQuery and having the followin problem.. I
I am having some problems with XML writing to a file. I am trying

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.