Converting DWG to TIFF always results in black and white images

Hello community,

I’ve been testing converting DWG files to TIFF using the .Net API in the Trial version, and it always generates black and white images, even though the DWG files are full color. Here’s the code we’re using:

using (var image = Image.Load(“H:\catastro_pak_3er_nivel_.dwg”))
{
// create an instance of CadRasterizationOptions and set page height & width
var rasterizationOptions = new Aspose.CAD.ImageOptions.CadRasterizationOptions()
{
PageWidth = 6400,
PageHeight = 6400
};

// create an instance of TiffOptions
var options = new Aspose.CAD.ImageOptions.TiffOptions(Aspose.CAD.FileFormats.Tiff.Enums.TiffExpectedFormat.TiffNoCompressionRgb);
// set the VectorRasterizationOptions property as CadRasterizationOptions
options.VectorRasterizationOptions = rasterizationOptions;

// export DWG to TIFF
image.Save(“H:\catastro_pak_3er_nivel_.tiff”, options);

Is there a parameter that’s incorrect or missing to generate a color TIFF output file? Or is there a limitation of the Trial license that always causes TIFF output files to be black and white?

I’d appreciate a response.

Best regards.

@ealvarezn

It seems that the issue you’re experiencing with converting DWG files to TIFF resulting in black and white images is related to the TIFF format options you are using. The default TIFF format option in the Aspose.CAD library supports only black and white images.

To generate a color TIFF output, you should use a different TIFF expected format that supports color. In your code, you are currently using TiffExpectedFormat.TiffNoCompressionRgb, which is correct for generating color images. However, ensure that the CadRasterizationOptions is properly configured to handle colors.

Here’s a revised version of your code that includes setting the background color and ensuring that the drawing colors are used:

using (var image = Image.Load("H:\\catastro_pak_3er_nivel_.dwg"))
{
    // Create an instance of CadRasterizationOptions and set page height & width
    var rasterizationOptions = new Aspose.CAD.ImageOptions.CadRasterizationOptions()
    {
        PageWidth = 6400,
        PageHeight = 6400,
        BackgroundColor = Aspose.CAD.Color.White, // Set a background color
        DrawType = Aspose.CAD.FileFormats.Cad.CadDrawTypeMode.UseDrawColor // Use the drawing color
    };

    // Create an instance of TiffOptions
    var options = new Aspose.CAD.ImageOptions.TiffOptions(Aspose.CAD.FileFormats.Tiff.Enums.TiffExpectedFormat.TiffNoCompressionRgb);
    // Set the VectorRasterizationOptions property as CadRasterizationOptions
    options.VectorRasterizationOptions = rasterizationOptions;

    // Export DWG to TIFF
    image.Save("H:\\catastro_pak_3er_nivel_.tiff", options);
}

Make sure that your DWG files contain the necessary color information and that the Aspose.CAD library is correctly set up to handle color output. If you continue to experience issues, it may be worth checking if there are any limitations with the trial version of the library that could affect the output.

If you have any further questions or need additional assistance, feel free to ask!

@ealvarezn,
Hi,
please use this option to get color image:

var rasterizationOptions = new Aspose.CAD.ImageOptions.CadRasterizationOptions()
    {
        PageWidth = 6400,
        PageHeight = 6400,
        BackgroundColor = Aspose.CAD.Color.White, // Set a background color
        DrawType = CadDrawTypeMode.UseObjectColor,
    };

Hi Oleksii!
Indeed, changing UseDrawColor to UseObjectColor generates color output.

Thanks and best regards!

1 Like

@ealvarezn,
we are happy to help :slight_smile: