Many Java applications need to transform photographic assets into lossless formats for printing or archival purposes. Conholdate.Total for Java provides a robust SDK that simplifies image processing tasks. In this guide you will learn how to convert JPG to TIFF in Java with just a few lines of code. We walk through the required setup, a detailed code walkthrough, and the options that control the output.

Prerequisites and Setup

Before you start, ensure you have the following:

  • Java Development Kit (JDK) 8 or higher.
  • Maven 3.x installed and configured.
  • An IDE such as IntelliJ IDEA or Eclipse (optional but recommended).
  • Access to the Conholdate.Total for Java SDK (downloadable from the official site).

Add the Conholdate Maven repository to your pom.xml:

<repositories>
    <repository>
        <id>conholdate-repo</id>
        <name>Conholdate Maven Repository</name>
        <url>https://repository.conholdate.com/repo/</url>
    </repository>
</repositories>

Then include the SDK dependency:

<dependency>
    <groupId>com.conholdate</groupId>
    <artifactId>conholdate-total</artifactId>
    <version>24.9</version>
    <type>pom</type>
</dependency>

You can download the latest SDK binaries from the download page. With the dependencies in place, you are ready to write code that will convert JPG to TIFF in Java.

Convert JPG to TIFF in Java: Step-by-Step Walkthrough

Step 1: Load the Source Image

Use the Image.load method to load the source JPG file. The Image class is part of the com.aspose.imaging package included in Conholdate.Total for Java.

com.aspose.imaging.Image image = com.aspose.imaging.Image.load("input.jpg");

Image.load detects the file format automatically and returns an Image object that you can save to another format.

Step 2: Create TiffOptions

Create an object of the TiffOptions class. It holds the settings used when the image is written as a TIFF file.

com.aspose.imaging.imageoptions.TiffOptions options = new com.aspose.imaging.imageoptions.TiffOptions(0);

The constructor argument selects the expected TIFF format. Passing 0 uses the default format, which is all you need for a standard JPG to TIFF conversion in Java.

Step 3: Save the Image as TIFF

Invoke the save method, pass the output path and the TiffOptions object as arguments, and the resulting image is written in TIFF format.

image.save("JPGToTIFF.tif", options);

If an error occurs, for example when the input file cannot be found, the SDK throws an exception that you can catch and log.

Step 4: Verify the Result

After the program finishes, check the output folder for JPGToTIFF.tif. Open the file with any TIFF viewer to confirm that the image was converted correctly.

Convert JPG to TIFF in Java - Complete Code Example

The following example combines the steps above into a runnable class that performs the JPG to TIFF conversion in Java using Conholdate.Total for Java.

import com.aspose.imaging.Image;
import com.aspose.imaging.imageoptions.TiffOptions;

public class JpgToTiffConverter {
    public static void main(String[] args) {
        // Load the source JPG image.
        Image image = Image.load("input.jpg");

        // Create an object of TiffOptions class.
        TiffOptions options = new TiffOptions(0);

        // Invoke the save method, pass TiffOptions as an argument
        // and save the resultant image in TIFF format.
        image.save("JPGToTIFF.tif", options);

        System.out.println("JPG to TIFF conversion completed successfully.");
    }
}

Note: This code example demonstrates the core functionality. Before using it in your project, make sure to update any file paths and configuration values to match your actual environment, verify that all required dependencies are properly installed, and test thoroughly in your development environment. If you encounter any issues, please refer to the official documentation or reach out to the support team for assistance.

Conversion Options and Settings

The conversion relies on two building blocks:

  • Image.load - Loads the source file. The input format is detected automatically, so the same approach works for other supported image formats.
  • TiffOptions - Defines how the TIFF file is written. The value passed to the constructor selects the expected TIFF format, and 0 gives the default format.

To write a different TIFF variant, change the value passed to the TiffOptions constructor and check the API reference for the available values and additional TiffOptions properties.

Conclusion

Converting JPG to TIFF in Java is straightforward with Conholdate.Total for Java. Load the image, create TiffOptions, and save, and the SDK handles the heavy lifting. Remember to review the licensing options on the pricing page and obtain a temporary license from the temporary license page before deploying to production. With the code and options covered in this guide, you can integrate image conversion into any Java application.

FAQs

How do I convert JPG to TIFF in Java without writing a lot of boilerplate code?
The Conholdate.Total for Java SDK reduces the conversion to three lines. Load the file with Image.load, create TiffOptions, and call image.save. The full example in this article shows the minimal code required.

What does the TiffOptions constructor argument mean?
It selects the expected TIFF format. The example passes 0 to use the default format. See the API reference for the other supported values.

Is it possible to perform batch JPG to TIFF conversion in Java?
Yes. Place the conversion logic inside a loop that iterates over a collection of JPG file paths. For each file, load the image, create TiffOptions, and save it under a unique output name.

Where can I find more examples and detailed API documentation?
Visit the official documentation for tutorials, and explore the API reference for class and method details.

Read More