Support to convert Image to Tiff with Ccitt4 compression

Hi,

I would like to have support from your side, because I am trying to convert jpg, bmp, gif and png file types to tiff files with ccitt4 compression. Attached file are the Input, and Output file. Also, I am using VS2010, Framework 4, and Imaging V.1.5.

I really appreciate your help.

Thank you,

Danilo Ac

danilo.ac@xerox.com

This is the currently source code I am using:

string filepath = "C:\\Taspose\\testimaging.JPG";

string fileoutput = "C:\\Taspose\\page2out.tiff";

System.IO.MemoryStream outStream = new System.IO.MemoryStream();

if (filepath != string.Empty)

{

try

{

Aspose.Imaging.License LIC = new Aspose.Imaging.License();

LIC.SetLicense("C:\\TAspose\\Aspose.total.lic");

using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(filepath))

{

//Get the saveOptions according to the value selected from dropdownlist

Aspose.Imaging.SaveOptions.TiffSaveOptions saveOptions = new Aspose.Imaging.SaveOptions.TiffSaveOptions();

saveOptions.Compression = Aspose.Imaging.FileFormats.Tiff.Enums.TiffCompressions.CcittFax4;

saveOptions.Photometric = Aspose.Imaging.FileFormats.Tiff.Enums.TiffPhotometrics.MinIsBlack;

saveOptions.BitsPerSample = 1;

saveOptions.SamplesPerPixel = 1;

//saveOptions.Xresolution = Convert.ToInt32(PDFResolution);

//saveOptions.Yresolution = Convert.ToInt32(PDFResolution);

//Save the image

image.Save(fileoutput, saveOptions);

image.Save(outStream, saveOptions);

}

//convert the MemoryStream to Byte array

Byte[] bytes = outStream.ToArray();

outStream.Close();

//Prepare the Response to output the file

/*Response.Clear();

Response.ClearHeaders();

Response.AddHeader("Content-Disposition", "attachment; filename=output." + this.ddlSaveType.SelectedItem.Value.ToLower());

Response.ContentType = "application/octet-stream";

Response.BinaryWrite(bytes);

Response.End(); */

}

catch (Exception ex)

{

LabelError.Text = ex.Message;

LabelError.ForeColor = System.Drawing.Color.Red;

}

}

Hi Danilo,


First of all please accept my sincere apology for the delayed response.

I am currently testing the beta version of Aspose.Imaging for .NET v1.6.0 against your requirement. I will keep you posted with updates on this.

Regards,

Hi Danilo,


Thank you for your patience.

I am afraid that the latest version of Aspose.Imaging produced the same results as shared by you in your original post. For investigation purposes, I have logged a ticket (IMAGING-33236) in our defect database and attached it to your request for tracking purposes. As soon as I hear anything in this regard, I will post here for your kind reference.

We are sorry for your inconvenience.

Hi Aspose Team,

Is there progress related to this topic?

Thank you,

Danilo Ac

danilo.ac@xerox.com

Hi Danilo,

Thanks for your inquiry. Above image conversion involves black and white color; unfortunately currently Aspose.Imaging doesn’t support this type of conversion. However, I have created a new feature request in our issue tracking system, IMAGING-33250. You will be notified via this forum thread once this feature gets available.

As a workaround please try following code snippet, used to convert color of image to black and white prior to format conversion. Hopefully it would serve the purpose.

using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(@"C:\temp\testimaging.JPG"))
{
    Aspose.Imaging.ImageOptions.TiffOptions saveOptions = new Aspose.Imaging.ImageOptions.TiffOptions();
    saveOptions.Compression = Aspose.Imaging.FileFormats.Tiff.Enums.TiffCompressions.CcittFax4;
    saveOptions.Photometric = Aspose.Imaging.FileFormats.Tiff.Enums.TiffPhotometrics.MinIsBlack;
    saveOptions.BitsPerSample = 1;
    saveOptions.SamplesPerPixel = 1;

    Color[] colors = (image as RasterImage).LoadPixels(image.Bounds);
    for (int i = 0; i < colors.Length; i++)
    {
        int power = colors[i].R + colors[i].G + colors[i].B;
        if (power > 380)
        {
            colors[i] = Color.Black;
        }
        else
        {
            colors[i] = Color.White;
        }
    }

    (image as RasterImage).SavePixels(image.Bounds, colors);
    image.Save(@"C:\temp\output.tiff", saveOptions);
}

Please feel free to contact us for any further assistance.

Best Regards

Hello

Any response to this request, I now need to save an image jpg grayscale, I use the library 1.7.1

Thanks

Hello,

I was facing a similar issue with the newest version of Aspose (1.7.1.0) and I tried the workaround presented here.
However, it does not work for me. The interesting thing, the output image is displayed differently in Paint and Irfan View - both incorrectly.

In the attached file you BMP-to-TIF-conversion-issue.7z you will find

Input.bmp - the original input file
Output (TIF-FAX4).TIF - the output file with FAX4 compression
Output (TIF-FAX4) - IrfanView vs Paint.jpg - comparison of the output (IrfanView vs Paint)

I saw another issue: when I try to save to TIF with the LZW compression, I get the result that can be seen in the file "Output (TIF-LZW).TIF"

The code that I use is below:

using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(fileSource))
{
var options = new Aspose.Imaging.ImageOptions.TiffOptions();
options.Compression = Aspose.Imaging.FileFormats.Tiff.Enums.TiffCompressions.Lzw;
image.Save(fileDest, options);
}

The issue is similar to the one reported here: <a href="https://forum.aspose.com/t/2321

Is there a progress in solving the issue already ?

Thanks
Rafal


Hi Roberto,


Thanks for your inquiry. I’m afraid above reported issue is still not resolved due to other priority tasks and complexity of the issue. However, I’ve requested ETA from development team and I’ll update you as soon as I get a feedback. Sorry for the inconvenience faced.

Hi Rafal,
In addition to above update, Thanks for the detailed analysis. I’ve also shared your findings with development team. Furthermore, mentioned issue is also related to the current thread issue and still not resolved. I’ll update you as soon as I get a ETA for the issue. Sorry for the inconvenience faced.

Best Regards,

So I take it color images conversion (like GIF to TIFF) is still not supported and will not be… I see this was posted a years ago??


Thanks

Hi Varouj,


Aspose.Imaging APIs support conversion of GIF files to TIFF format regardless of the colors. Please give a try to the following piece of code against your sample GIF. Please note, the code will generate the TIFF in JPEG compression with RGB color space. If you intend to output the image in any other compression, please check the details for TiffOptions Configuration. Moreover, it is best you try the latest version of the API, that is 3.1.0 at the moment.

Please feel free to contact us back in case you face any difficulty or have more questions for us.

C#

using (Image image = Image.Load(“D:/sample.gif”))
{
image.Save(“D:/output.tiff”, new TiffOptions(TiffExpectedFormat.TiffJpegRGB));
}

The issues you have found earlier (filed as ) have been fixed in this Aspose.Words for JasperReports 18.3 update.