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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T01:48:49+00:00 2026-05-31T01:48:49+00:00

I have a java.awt.Image that I need to add CCITT T.6 compression and convert

  • 0

I have a java.awt.Image that I need to add CCITT T.6 compression and convert to a TIFF byte array. I have seen some examples of using TIFFImageWriteParam and other classes from the javax.imageio package but I can’t find a complete example going all the way from Image to byte array.

Here is what I have so far beginning with a java.awt.Image obtained from scanning. This works just fine to generate a byte array of a TIFF, but I need to find a way, using TIFFImageWriteParam or some other means, to compress the TIFF prior to processing it as a byte array:

thisImage = ... a java.awt.Image from a scanner
if(thisImage!=null){

  ByteArrayOutputStream baos = new ByteArrayOutputStream();
  BufferedImage bimg = new BufferedImage(thisImage.getWidth(null),thisImage.getHeight(null), BufferedImage.TYPE_BYTE_BINARY);  
  bimg.createGraphics().drawImage(thisImage, 0, 0, null);

  try {
    ImageIO.write(bimg, "tiff", baos);                  
  } catch (Exception e) {
    e.printStackTrace();
  }

  thisByteArray = baos.toByteArray();

  ...

Any help would be appreciated.

  • 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-31T01:48:50+00:00Added an answer on May 31, 2026 at 1:48 am

    I found a solution thanks to: this thread.

    Here is what I ended up doing that solved my issue:

    thisImage = thisImage = ... a java.awt.Image from a scanner
    if(thisImage!=null){  
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
      boolean foundWriter = false;
      BufferedImage bimg = new BufferedImage(thisImage.getWidth(null),thisImage.getHeight(null), BufferedImage.TYPE_BYTE_BINARY);
      bimg.createGraphics().drawImage(thisImage, 0, 0, null); 
      for(Iterator<ImageWriter> writerIter = ImageIO.getImageWritersByFormatName("tif"); writerIter.hasNext() && !foundWriter;) {
        foundWriter = true;
        ImageWriter writer = (ImageWriter)writerIter.next();
        writer.setOutput(ios);
        TIFFImageWriteParam writeParam = (TIFFImageWriteParam)writer.getDefaultWriteParam();
        writeParam.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
        writeParam.setCompressionType("CCITT T.6"); 
        writer.prepareWriteSequence(null);
        ImageTypeSpecifier spec = ImageTypeSpecifier.createFromRenderedImage(bimg);
        javax.imageio.metadata.IIOMetadata metadata = writer.getDefaultImageMetadata(spec, writeParam);
        IIOImage iioImage = new IIOImage(bimg, null, metadata);
        writer.writeToSequence(iioImage, writeParam);
        bimg.flush();
        writer.endWriteSequence();
        ios.flush();
        writer.dispose();
        ios.close();
        thisByteArray = baos.toByteArray(); 
        baos.close();
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Java Applet that uses AWT. In some (rare) circumstances, the platform
I have a Serializable object which is supposed to hold a java.awt.Image as its
I have a Graphics object of JPanel and that is working fine: import java.awt.Color;
I'm trying to convert an Image object to a byte array then back to
I have a Java Applet that is generating an image. Ultimately, I would like
I have subclassed java.awt.Frame and have overridden the paint() method as I wish to
I have two questions about java.awt.Shape . Suppose I have two Shape s, shape1
I am trying to mock java.awt.Toolkit.beep() using JMockit Expectations. I have the following code
I have the following code adding an ActionListener to a JTextField: chatInput.addMouseListener(new java.awt.event.MouseAdapter() {
We have a Java Applet built using AWT. This applet lets you select pictures

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.