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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T23:49:17+00:00 2026-05-15T23:49:17+00:00

I want to dynamically create some image from Java and save it to a

  • 0

I want to dynamically create some image from Java and save it to a file.
As I read in various tutorials, I need to use BufferedImage.

But, the BufferedImage constructor requires that the height and width as parameters. But I don’t know the final size of my image. How should I create an image with size unknown in advance?

There are two obvious strategies:

  1. Create a very large image initially, say 10000×10000.
  2. Gradually creating larger image, and copying the original to it. The drawback is that I need to check the bounds before each time I want to add something.

How do you deal with this problem?

  • 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-15T23:49:18+00:00Added an answer on May 15, 2026 at 11:49 pm

    You’ve just run into space vs time issue here. I would be going for the first strategy of creating a very large image 10000×10000, the simple reason being the second approach you say involves mountains of matrix copies which you would want to avoid at any cost.

    Moreover, with a good knowledge of the image size, you can further optimize that value of 10000 x 10000 to something like 1000×1000 initially. If the image seems to exceed this, double it like 2000 x 2000 and copy the old one to the new one and keep doing this as your image expands.. This is more of a proven strategy that is used in the famous java.util.ArrayList

    By this way, you are indirectly bridging the time vs space trade-off. And yes, you will have to calculate the bounds everytime but that does not look a big task to me, it can be done in O(1) time.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to use JavaCompiler to dynamically create some classes. I found the source
I want to be able to dynamically create ViewControllers based on a JSON file.
I want create some view, and add dynamically to it text and images Somebody
i have an array of some values and i want to dynamically create textfields
I want to dynamically create a 1-row grid and add some TextBlocks to it,
i've got some binary data which i want to save as an image. When
I want to combine some images with PHPGD to create a CSS Sprite dynamically,
I need to dynamically create some views in my app and place some buttons
I'm trying to dynamically create objects out of forms, but I want some reduntant
I want to dynamically create instance method of child class through class method of

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.