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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T08:53:37+00:00 2026-05-12T08:53:37+00:00

I have been given a bit of a strange task, there are around 1500-2000

  • 0

I have been given a bit of a strange task, there are around 1500-2000 jpeg images all of around 1-50kb in size. They are currently stored in a simple database I made with Postgres. It’s been a long time since I used Matlab and Postgres heavily so any help or suggestions is really appreciated!

I need to get the images that are stored in the database, out of the database into Java. The last step is retrieve the image from Java into Matlab so that the image is stored in the same way in which the imread function works in Matlab. The imread function reads an image in and creates a n by m by 3 matrix array of uint8 values which denote the pixel intensities of RGB.

Atm I have got the image in and out of the database in Java, currently storing the image in a bytea column data type. Is the best data type to use?

How can I get the data back out from the database, so that it is either the constructed jpeg image which I put in or is in the requested matrix array format?

Currently I do not understand the retrieved data. It is in a byte array of around 70,000 elements containing values between -128 to 128. Help!?!

Note: The database toolkit is unavailable to me

ANOTHER UPDATE: I have solved the problem related to the post regarding’UTF-8′ encoding error.

If anyone stumbles upon this page, any answer posted will be tried as soon as I can! I really do appreciate your thoughts and answers. Thanks again.

  • 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-05-12T08:53:38+00:00Added an answer on May 12, 2026 at 8:53 am

    Problem solved 🙂

    I have managed to get the bytes stored within the bytea column within the database into a byte array. Then through creating a temp file ( using ByteArrayInputStream and Reader object to form a BufferedImage object which I write to a file) send this back into Matlab in an array.

    Then process the data I retrieved and read from the temporary file in Matlab. Once the data is within Matlab all the temp files are deleted.

    The code to process the ResultSet to create a temp image from a byte array received from the databases bytea column is shown below:

    private static void processImageResultSet(ResultSet rs) throws SQLException, FileNotFoundException, IOException{
    
            int i = 0;                  //used as a count and to name various temp files
            while(rs.next()){           //loop through result sets
    
            byte[] b = rs.getBytes(1);                                 //the bytea column result
            String location = getFileName(rs.getString(2));            //the name of the jpg file
            ByteArrayInputStream bis = new ByteArrayInputStream(b);    //creates stream storing byts
    
            //To make individual names of temporary files unique the current time and date is stored
            SimpleDateFormat df = new SimpleDateFormat("'Date 'yyyy-MM-dd HH'H'-mm'M'-ss'secs'-SS'ms'"); //formats date string
            Calendar cal = Calendar.getInstance();                                //gets instance of calendar time
            String fileDate = df.format(cal.getTime());                           //gets the time and date as a String
    
            Iterator<?> readers = ImageIO.getImageReadersByFormatName("jpg");     //creates a reader object, that will read jpg codec compression format
            Object source = bis;                                                  //object to store stream of bytes from database
            ImageReader reader = (ImageReader) readers.next();                      
            ImageInputStream iis = ImageIO.createImageInputStream(source);        //creates image input stream from object source which stores byte stream
    
            reader.setInput(iis, true);             //sets the reader object to read image input stream
    
            ImageReadParam param = reader.getDefaultReadParam(); 
            Image image = reader.read(0, param);
    
            BufferedImage bufferedImage = new BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_RGB);   //creates buffered image
    
            Graphics2D g2 = bufferedImage.createGraphics();
            g2.drawImage(image, null, null);
            File imageFile = new File(location + " " + fileDate + " " + i + ".jpg"); //creates image file 
            ImageIO.write(bufferedImage, "jpg", imageFile);                          //writes buffered image object to created file
    
            i++;        //counts number of results from query within the ResultSet 
            }
    
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have been given a site xyz.com, in which the home page has images
I have been given the task of adding functionality to an existing IIS 6.0
I have been given the unenviable task of cleaning up after a developer who
I have recently been given a task to add the ability to interact with
I have been given the format for page table entries: Bit 23: Valid Bit
I have been given the task of finding a replacement for a piece of
i Have been given this simple task , I want to connect to facebook
I was given this bit of Scheme code, and have been tasked with translating
Hi I am a bit new to programming and recently I have been given
I have been given the following programming task (edited to obscure mission-specifics): The raw

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.