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 9217855
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:43:35+00:00 2026-06-18T02:43:35+00:00

I’ve designed a rest service to respond the images stored in the database for

  • 0

I’ve designed a rest service to respond the images stored in the database for the users. The service works fine. The service responds the images in jpg format. If the user uploads the image in the jpg format the the response is also fine, if the image is some other formats, then the response cannot be rendered as image. I need to construct a jpg converter or encoder, for all the input image types. Is there are any possible way to achieve this.

  • 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-18T02:43:37+00:00Added an answer on June 18, 2026 at 2:43 am

    You should take a look at ImageIO. It has support for reading and writing JPEG, PNG, BMP, WBMP and GIF.

    The JAI API also supplies TIFF support and I’ve used a RAW plugin for Nikon cameras before as well.

    Check out Working with Images and the JavaDocs for more info.

    Updated with Example

    Without the source image is not going to be possible to do a proper test, but this is the basic work flow.

    I’ve used File as my inputs, but to demonstrate the basic concept, I’ve create InputStream and OutputStream (as ImageIO can read/write Files)

    File inputFile = new File("/path/to/image.png");
    File outputFile = new File("Test.jpg");
    try (InputStream is = new FileInputStream(inputFile)) {
        BufferedImage image = ImageIO.read(is);
        try (OutputStream os = new FileOutputStream(outputFile)) {
            ImageIO.write(image, "jpg", os);
        } catch (Exception exp) {
            exp.printStackTrace();
        }
    } catch (Exception exp) {
        exp.printStackTrace();
    }
    

    Updated

    So using the above code, I was able to convert a PNG file I created in paint to JPG…

    PNG/JPG

    enter image description hereenter image description here

    You could also try converting the input stream and output stream to an ImageInputStream and ImageOutputStream, although this is normally done when you want to look up the providers for a given image format.

    File inputFile = new File("...");
    File outputFile = new File("Test.jpg");
    try (InputStream is = new FileInputStream(inputFile)) {
        ImageInputStream iis = ImageIO.createImageInputStream(is);
        BufferedImage image = ImageIO.read(iis);
        try (OutputStream os = new FileOutputStream(outputFile)) {
            ImageOutputStream ios = ImageIO.createImageOutputStream(os);
            ImageIO.write(image, "jpg", ios);
        } catch (Exception exp) {
            exp.printStackTrace();
        }
    } catch (Exception exp) {
        exp.printStackTrace();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I'm outputting a post title and in our database, it's Hello Y’all
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am using JSon response to parse title,date content and thumbnail images and place
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I have a view passing on information from a database: def serve_article(request, id): served_article
I have a reasonable size flat file database of text documents mostly saved in
I need to clean up various Word 'smart' characters in user input, including but
I have a bunch of posts stored in text files formatted in yaml/textile (from
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function

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.