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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T09:54:10+00:00 2026-05-25T09:54:10+00:00

I need to add specific padding around large images and the current method I

  • 0

I need to add specific padding around large images and the current method I am using, as seen in the snippet below, is eating up memory. Opening the PNG sucks up ~300mb of memory right off the bat and making a copy of that pushes me past 700mb so I am looking for a way to do this without sucking up all available memory. Any suggestions?

...
BufferedImage img = ImageIO.read(new File("OldWorld.png"));
BufferedImage img2 = new BufferedImage(img.getHeight()+padding,img.getWidth()+padding, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2 = img2.createGraphics();
g2.setPaint(new Color(0,0,0,0);
g2.fillRect(0, 0, img.getHeight()+padding, img.getWidth()+padding);
g2.drawImage(img, img.getHeight(),img.getWidth(), null);
...
  • 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-25T09:54:11+00:00Added an answer on May 25, 2026 at 9:54 am

    There is no direct way to solve this.
    Working with large images in Java consumes a lot of memory.

    Some alternatives are:

    1. Pre-process your images with the netpbm library
      http://netpbm.sourceforge.net/.
      To pad an image use a command like:

      pngtopnm OldWorld.png | pnmpad -black 48 -left 48 -top 48 | pnmtopng > padded.png
      
    2. Reduce the number of colors in your image so that you can use image type
      BufferedImage.TYPE_INDEXED with only one byte per pixel instead of four.

    3. Use a several tiles instead of a single large image and work
      with one tile at a time. Then you avoid having a lot of image
      data in memory.

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

Sidebar

Related Questions

I need to add a specific column if it does not exist. I have
I need to add a dependency on a specific version of GDIPlus. This is
Users need to be able to add a specific type of column to an
I'm using a bit of jQuery to expand/hide some divs. I need to add
I need to add an Anchor with a specific ClickHandler into an Element. But
I have a problem using Infragistics UltraTree control. I need a way to add
I am using GCC, what switches do I need to add to link with
I need to add classes to li items in a ul #colorlist at specific
I need to add my picture as a popup to google maps specific address
I am using POI to generate an Excel File. I need to add borders

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.