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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:19:30+00:00 2026-06-14T06:19:30+00:00

I have a Java program that creates composite png images that contain only black

  • 0

I have a Java program that creates composite png images that contain only black pixels and 100% transparent pixels. I am trying to reduce the size of these composites as much as possible and I notice that ImageIO.write always outputs 32 bit PNG’s. I would like to instead save them as 8-bit considering that the images will only have two colors total but I don’t think there is a way to do this with the standard Java functions.

Does anyone know of any pre-built functions that will create an 8-bit png from a BufferedImage? Any other advice to reduce the size of these png’s is welcome too!

  • 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-14T06:19:31+00:00Added an answer on June 14, 2026 at 6:19 am

    I had to put this in the backseat for a bit, but I came back to it yesterday and figured out how to do it. Basically it came down to using the classes under com.sun.imageio.plugins.png and a custom ImageWriteParam.

    I had to build the color tables myself (not too hard, just byte arrays). The color tables were then passed to ImageTypeSpecifier.createIndexed. The resulting ImageTypeSpecifier returned allows you to create a BufferedImage into which I copied the pixels.

    Next, I created custom PNG headers by using PNGMetadata (Needed to read up a lot on the PNG specification, but overall very easy). I then created a new IIOImage using said metadata and the BufferedImage.

    Finally, I created a PNGImageWriter and got the default ImageWriteParam from it. I then simply passed the ImageTypeSpecifier from before to its setDestinationType method. Last step was to write the PNG to disk by passing the IIOImage and the ImageWriteParam to the PNGImageWriter.

    The documentation is very sparse on many of these classes but their functionality is great. By doing this, I created a minimal PNG that contained a bit depth of 1 (since there are only two colors) and this reduced the size of my PNG’s by an average of 78%!!! Very much worth the effort.

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

Sidebar

Related Questions

I have a Java program that creates a file and prints a bunch of
My question is I have to write a program in java that creates different
I have a java program which creates a lock file to ensure that no
I have a simple java program that creates a series of temporary files stored
I have a Java program that creates a server socket and accepts connections from
I have a program with Driver GUI java file that creates a JFrame and
I have a java program that performs 5 different tasks. When I run the
I have a java program that is running in the background(Windows). I would like
I have a Java program that runs many small simulations. It runs a genetic
I have a java program that will work with a variety of Java Beans.

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.