How to Convert multiple 32bpp multi-frame TIFF MemoryStreams to one Group 4 1bpp B&W Grayscale MemoryStream

We need to convert multiple 32bpp TIF sources - all are provided via MemoryStream TIFs - to a single CCITT4 1bpp grayscale TIF MemoryStream which is then returned.
All TIFs may contain one or more frames.
The object may also be converted to grayscale PDF MemoryStream - but not all the time.
The conversion algorithms and built-in types I have found in Aspose drop the gray-scaled logo on the cover sheet completely (built-in specifying IsBlackWhite=true and also using WinAPIIndexBitmapConverter()).

We need to convert to standard G4 black and white grayscaled image - not either black or white.

The method I am writing is called inside BizTalk and speed is important.

Ideally the ultimate solution would be methods like these two returning 1bpp MemoryStreams:
MemoryStream Convert32bppTIFtoG4GrayscaleTIF(MemoryStream ms32bppTIFIn)
which could then be used separately and by:
MemoryStream Convert32bppTIFArraytoG4GrayscaleTIF(MemoryStream [] msArrayOf32bppTIFIn)

There is an older post requesting this - but no update or info how to with current resources (https://forum.aspose.com/t/128073)
(Our company has ordered Aspose.Total - so all will be available)

Our current code - using samples found on various pages on your forum and documentation does work for strictly Black and White - but I need to do Grayscale conversions.

public static MemoryStream GetStreamOfReportAndImages(...)
{

// Get the cover page sheet as a TIFF image MemoryStream
// Note that this is a 32 bit tiff and will require conversion
MemoryStream report = GetReport(reportName); // returns stream of CoverPage

//Instantiate Pdf instance by calling its empty constructor
Aspose.Pdf.Generator.Pdf pdf1 = new Aspose.Pdf.Generator.Pdf();

//Add a section into the pdf document
Aspose.Pdf.Generator.Section sec = pdf1.Sections.Add();

//Create an image object in the section
Aspose.Pdf.Generator.Image imageht = new Aspose.Pdf.Generator.Image(sec);

//Set the type of image using ImageFileType enumeration
imageht.ImageInfo.ImageFileType = Aspose.Pdf.Generator.ImageFileType.Tiff;
imageht.ImageInfo.TiffFrame = -1;
//imageht.ImageInfo.IsBlackWhite = true;
// Specify the image source of initial pdf as MemoryStream
imageht.ImageInfo.ImageStream = report;
//Add image object into the Paragraphs collection of the section
sec.Paragraphs.Add(imageht);

// Add TIFs from imagePaths array
for (int i = 0; i < imagePaths.Length; i++)
{
// Specify the image source as MemoryStream
using (Stream imageFile = new FileStream(imagePaths[i], FileMode.Open, FileAccess.Read))
{
byte[] tmpBytes = new byte[imageFile.Length];
imageFile.Read(tmpBytes, 0, Convert.ToInt32(imageFile.Length));
MemoryStream copiedStream = new MemoryStream(tmpBytes);
copiedStream.Seek(0, SeekOrigin.Begin);
System.Drawing.Bitmap b = new System.Drawing.Bitmap(copiedStream);
//Create a new section in the Pdf document
sec = new Aspose.Pdf.Generator.Section(pdf1);
// Set margins so image will fit, etc.
sec.PageInfo.Margin.Top = 2;
sec.PageInfo.Margin.Bottom = 2;
sec.PageInfo.Margin.Left = 2;
sec.PageInfo.Margin.Right = 2;
sec.PageInfo.PageWidth = (b.Width / b.HorizontalResolution) * 72;
sec.PageInfo.PageHeight = (b.Height / b.VerticalResolution) * 72;
//Add the section in the sections collection of the Pdf document
pdf1.Sections.Add(sec);
//Create an image object
imageht = new Aspose.Pdf.Generator.Image(sec);
//Add the image into paragraphs collection of the section
imageht.ImageInfo.ImageFileType = Aspose.Pdf.Generator.ImageFileType.Tiff;
// set IsBlackWhite property to true for performance improvement
imageht.ImageInfo.IsBlackWhite = true;
// import ALL pages of TIFF
imageht.ImageInfo.TiffFrame = -1;
//Set the ImageStream to a MemoryStream object
imageht.ImageInfo.ImageStream = copiedStream;
//Set desired image scale
imageht.ImageScale = 1.0F; // 0.95F;
//Add image object into the Paragraphs collection of the section
sec.Paragraphs.Add(imageht);
if (b != null)
b.Dispose();
}
}

// Create base PDF for future processing
Aspose.Pdf.Document newPdf = new Aspose.Pdf.Document(pdf1);
//newPdf.Save(@"C:\Temp\newPdf_test.pdf"); // /test save all pages to PDF file

pageCount = newPdf.Pages.Count;

//create TiffSettings object
TiffSettings tiffSettings = new TiffSettings();
tiffSettings.Compression = CompressionType.CCITT4;
tiffSettings.Depth = ColorDepth.Format1bpp;

//create TIFF device
TiffDevice tiffDevice = new TiffDevice(PageSize.PageLetter, tiffSettings, new WinAPIIndexBitmapConverter());

//convert a particular page and save the image to stream
tiffDevice.Process(newPdf, mergedImage);
// Output to TIF MemoryStream

if (format == ReportFormatType.PDF)
{

// output requested is PDF - reconvert new 1bpp TIF to PDF MemoryStream
Aspose.Pdf.Generator.Pdf pdfout = new Aspose.Pdf.Generator.Pdf();
Aspose.Pdf.Generator.Section secout = new Aspose.Pdf.Generator.Section(pdfout);
// Set margins so image will fit, etc.
secout.PageInfo.Margin.Top = 0;
secout.PageInfo.Margin.Bottom = 0;
secout.PageInfo.Margin.Left = 0;
secout.PageInfo.Margin.Right = 0;
pdfout.Sections.Add(secout);
//Create an image object in the section
Aspose.Pdf.Generator.Image imageout = new Aspose.Pdf.Generator.Image(secout);
//Set the type of image using ImageFileType enumeration
imageout.ImageInfo.ImageFileType = Aspose.Pdf.GeneratorImageFileType.Tiff;
imageout.ImageInfo.TiffFrame = -1;
//imageout.ImageInfo.IsBlackWhite = true;
imageout.ImageScale = 1.0F;
;/Add image object into the Paragraphs collection of the section
secout.Paragraphs.Add(imageout);
// Specify the image source as MemoryStream
imageout.ImageInfo.ImageStream = mergedImage;
//pdfout.Save(@"C:\Temp\TifToPDFBW.pdf"); // uncomment and comment below Save to test
// Output to PDF MemoryStream

pdfout.Save(mergedImage);

}

newPdf.Dispose();
return mergedImage;
}

Hi Todd,


Thanks for your inquiry. We are looking into your requirements and will get back to you soon.

Best Regards,

Please rush this request

  • our purchase of Aspose.Total is totally dependent upon this functionality.

Again the summary:
Need to get from TIF MemoryStream’s to both a PDF and single Group 3 (or 4? our prior competitors code was CCIT 3).

The Settings to use appear to be unknown or inaccurate - The source TIF contains a color logo image on the FAX. I have coded to convert this to grayscale successfully, and I can save it to PDF in the grayscale state.

The Problem:

  • I cannot save the PDF as a multi-page TIF using TiffDevice or add the grayscale bitmaps as a multi-page using TiffImage or TiffFrame.

I continue to try - Current C# Code below - seems to almost work but adds black first page - why? and I do not know how to get the output to a standard grayscale group 3 fax - changing to these settings seems to cause output to go solid black where logo is or show messed up images:

// 30-DAY TEMP LICENSE CALLED IN CLASS INIT

// GetReport(…) returns a TIF Cover page with Grayscale Logo in 2-4 page TIF
MemoryStream report = GetReport(reportPath, ReportFormatType.TIFF, parameters);

// bitmap container for converted to grayscale bitmap
System.Drawing.Bitmap btGray;

//Instantiate Pdf instance by calling its empty constructor
Aspose.Pdf.Generator.Pdf pdf1 = new Aspose.Pdf.Generator.Pdf();

// Create an Image container from TIF stream
System.Drawing.Image ImageCopy = System.Drawing.Image.FromStream(report);

int reportpageCount = ImageCopy.GetFrameCount(FrameDimension.Page);

Guid objGuid = ImageCopy.FrameDimensionsList[0];

FrameDimension objDimension = new FrameDimension(objGuid);

// Stream container for individual pages
MemoryStream tempTIFF;

// WHAT ARE THE CORRECT SETTINGS TO GET A STANDARD GRAYSCALE GROUP3? FAX
Aspose.Imaging.ImageOptions.TiffOptions createOptions = new Aspose.Imaging.ImageOptions.TiffOptions();
createOptions.Compression = Aspose.Imaging.FileFormats.Tiff.Enums.TiffCompressions.CcittFax3;
createOptions.Xresolution = ImageCopy.HorizontalResolution;
createOptions.Yresolution = ImageCopy.VerticalResolution;
createOptions.BitsPerSample = 8;
createOptions.SamplesPerPixel = 3;
createOptions.Orientation = Aspose.Imaging.FileFormats.Tiff.Enums.TiffOrientations.TopLeft;
createOptions.ResolutionUnit = Aspose.Imaging.FileFormats.Tiff.Enums.TiffResolutionUnits.Centimeter;
createOptions.PlanarConfig = Aspose.Imaging.FileFormats.Tiff.Enums.TiffPlanarConfigs.Contig;
createOptions.Photometric = Aspose.Imaging.FileFormats.Tiff.Enums.TiffPhotometrics.Rgb;

// THIS IS NOT CORRECT COMPRESSION BUT DOES PRODUCE GRAYSCALE

createOptions.Compression = Aspose.Imaging.FileFormats.Tiff.Enums.TiffCompressions.Lzw;

createOptions.Source = new Aspose.Imaging.Sources.StreamSource(new System.IO.MemoryStream(), true);

using (TiffImage timage = (TiffImage)Aspose.Imaging.Image.Create(createOptions, ImageCopy.Width, ImageCopy.Height))
{
    for (int ipagenumber = 0; ipagenumber < reportpageCount; ipagenumber++)
    {
        tempTIFF = new MemoryStream();

        ImageCopy.SelectActiveFrame(objDimension, ipagenumber); // load that page

        // CopyToB(..) returns a Grayscale Bitmap of passed in Bitmap
        btGray = CopyToB(ImageCopy.Clone() as Bitmap);

        // Save GrayScale Bitmap as type TIFF MemoryStream
        btGray.Save(tempTIFF, ImageFormat.Tiff);

        // reset stream to ensure it is at start of TIF
        tempTIFF.Seek(0, SeekOrigin.Begin);

        //Load Grayscale TIF image and save to a Frame in timage
        RasterImage imageAdd = (RasterImage)Aspose.Imaging.Image.Load(tempTIFF);
        TiffFrame frameAdd = TiffFrame.CreateFrameFrom(timage.ActiveFrame, createOptions);

        frameAdd.SavePixels(imageAdd.Bounds, imageAdd.LoadPixels(imageAdd.Bounds));
        timage.AddFrame(frameAdd);

        // save page to see if it loaded the timage properly
        timage.Save(@"C:\Temp\tFrame" + ipagenumber.ToString() + ".tif", true);

        // Save stream Load all tiff files in byte array
        Bitmap b = new Bitmap(tempTIFF);

        //Create a new section in the Pdf document
        Aspose.Pdf.Generator.Section sec1 = new Aspose.Pdf.Generator.Section(pdf1);

        // Set margins and page size so image will fit based on TIF image
        sec1.PageInfo.Margin.Top = 5;
        sec1.PageInfo.Margin.Bottom = 5;
        sec1.PageInfo.Margin.Left = 5;
        sec1.PageInfo.Margin.Right = 5;
        sec1.PageInfo.PageWidth = (b.Width / b.HorizontalResolution) * 72;
        sec1.PageInfo.PageHeight = (b.Height / b.VerticalResolution) * 72;

        //Add the section in the sections collection of the Pdf document
        pdf1.Sections.Add(sec1);

        //Create an image object
        Aspose.Pdf.Generator.Image image1 = new Aspose.Pdf.Generator.Image(sec1);

        //Add the image into paragraphs collection of the section
        sec1.Paragraphs.Add(image1);

        image1.ImageInfo.ImageFileType = Aspose.Pdf.Generator.ImageFileType.Tiff;

        // set IsBlackWhite property to true for performance improvement
        //image1.ImageInfo.IsBlackWhite = true; // THIS DESTROYS GRAYSCALE
        //Set the ImageStream to a MemoryStream object
        image1.ImageInfo.ImageStream = tempTIFF;

        //Set desired image scale
        image1.ImageScale = 1.0F;
    }

    // TEST save file –
    timage.Save(@"C:\Temp\TiffImage.tif", true);
}

// TEST save PDF file - successful
pdf1.Save(@"C:\Temp\t.pdf");

// Create base PDF for save to TIF
Aspose.Pdf.Document newPdf = new Aspose.Pdf.Document(pdf1);
pageCount = newPdf.Pages.Count;

// Save pdf to 1bpp TIF Image MemoryStream 
//create TiffSettings object
TiffSettings tiffSettings = new TiffSettings();
tiffSettings.Compression = CompressionType.CCITT3;
tiffSettings.Depth = ColorDepth.Default;// ColorDepth.Format1bpp;

//create TIFF device
Resolution resolution = new Resolution(200);

// Using WinAPIIndexBitmapConverter fails as it always fails to convert bitmap properly

//TiffDevice tiffDevice = new TiffDevice(PageSize.PageLetter, resolution, tiffSettings, new WinAPIIndexBitmapConverter());

TiffDevice tiffDevice = new TiffDevice(tiffSettings);

//convert a particular page and save the image to stream
tiffDevice.Process(newPdf, @"C:\Temp\tiffDevice.tif");
}

Sorry, I neglected to include a called method for converting to Grayscale - here it is:

private static Bitmap CopyToB(System.Drawing.Bitmap original)
{
    Bitmap newBitmap = new Bitmap(original.Width, original.Height);
    System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(newBitmap);
    float[][] colorMatrixElements = {
                new float[] {0.3F, 0.3F, 0.3F, 0, 0},
                new float[] {0.59F, 0.59F, 0.59F, 0, 0},
                new float[] {0.11F, 0.11F, 0.11F, 0, 0},
                new float[] { 0, 0, 0, 1, 0},
                new float[] { 0, 0, 0, 0, 1}};

    System.Drawing.Imaging.ColorMatrix c = new System.Drawing.Imaging.ColorMatrix(colorMatrixElements);
    System.Drawing.Imaging.ImageAttributes attributes = new System.Drawing.Imaging.ImageAttributes();
    attributes.SetColorMatrix(c);
    g.DrawImage(original, new System.Drawing.Rectangle(0, 0, original.Width, original.Height), 0, 0, original.Width, original.Height, System.Drawing.GraphicsUnit.Pixel, attributes);
    g.Dispose();
    return newBitmap;
}

Hi Todd,


Sorry for the inconvenience faced. Can you please share your sample input, current output and expected output files here. It would help us in our investigation and will provide your information accordingly.

Best Regards,

I have attached a tifsamples.zip file containing these files to the above message I posted.
(Seems I could not make this reply Private - but could make that one private - the tifs contain our company name and management prefers me not to publish it.

The results of earlier tries - the Tiffoutput.tif Tiff file shows the expected output - in color.

The input comes from two types of sources - MemoryStream TIFs and TIF files.

Pages 1-3 of the sample came from a TIF MemoryStream named report shown in code above:
A tif saved from the report stream looks like the ReportStreamIn.tif file - I do not have the exact source.
Early attempts with the newer code, using TiffImage and trying to save each TIF page to it resulted in badheader.tif.

The remaining pages 4-12 - come from external loaded Tif files passed in an array and converted to streams. These would look like the Additionaltifs.tif file.

My latest attempt was using a modified version of https://forum.aspose.com/t/2140

and I do not understand why it adds a black page to the first... And - it totally fails to add the second set of files (not shown in the second code sample).

I tried:

using (TiffImage timage2 = (TiffImage)Aspose.Imaging.Image.Load(copiedStream)) {
int id = 0;
timage2.Save(@"C:\Temp\TiffImage2.tif", createOptions);
foreach (TiffFrame tf in timage2.Frames)
{
tempTIFF = new MemoryStream();
tf.Save(tempTIFF, createOptions);
tempTIFF.Seek(0, SeekOrigin.Begin);
RasterImage imageAdd = (RasterImage)Aspose.Imaging.Image.Load(tempTIFF);
imageAdd.Save(@"C:\Temp\TiffImageAdd" + id.ToString() + ".tif");
TiffFrame frameAdd = TiffFrame.CreateFrameFrom(timage.ActiveFrame, createOptions);
frameAdd.SavePixels(imageAdd.Bounds, imageAdd.LoadPixels(imageAdd.Bounds));
TiffFrame frame1 = frameAdd;
timage.AddFrame(frame1);
id++;
tempTIFF.Dispose();
}
}

or something like:
timage.AddFrames(timage2.Frames as TiffFrame []);// failed immediately

the first above almost worked - apparently cannot get image or convert it and saved bad tifs for pages 4 to 12. I tried calling tf.Save( filename, tif) and it saved garbage - so cannot read image from TiffFrame tf?

All we want to do is get the same output as shown in Tiffoutput.tif in Grayscale in both TIF and PDF MemoryStream objects.

Thanks for your help,

Todd

HI Todd,


Thanks for providing additional information. Our development team is looking into your requirements for the purpose I've logged an issue in our issue tracking system as IMAGING-33437 for investigating your required compression. I will update you soon with findings via this forum thread.


Thanks for your patience and coordination.


Best Regards,

I have coded to create grayscaled versions of the PDF and TIF files - sample code attached.
But cannot get the output format to Group 3 CcittFax3 format.

All I can get is gray-scaled True color (24 bit) output in LZW compression format - which is NOT viewable using the Microsoft Preview and cannot be opened in MS Paint, and I was told LZW is not acceptable as an input format to further processing.

The output must be as a normal FAX Group 3, which I assume is TiffCompressions.CcittFax3.
TiffCompressions.CcittFax4 may be okay, but 3 is preferred.

I have attached my current almost working code file for further reference.

Hi Todd,


Thanks for sharing the details. We are working over your query and will get back to you soon.

Best Regards,

I have successfully implemented a work-around (with known performance problems) - after discovering some of the problems with the Aspose.Imaging. It requires the TIF image added to be at the same resolution, page size, and specs as the output images. Major problems occurred when trying to get a second set of TIF images added to an already started TIFFImage which was a different sized document (like 1700x2300 vs 1776 x 2462) - attempting to add, one at a time, individual TIF frames using TIF MemoryStreams of them using Microsoft to split the second source to individual active pages - failed.
My workaround - I wrote a routine to export the active frame, us MS Image to resize it as a 32bpp image, save it as a CompressionCCITT3 1bpp TIF and then return that. I was able to create the resulting TIF Image set. The problem with this fix was - I could not get it to be right - no matter what settings I tried - it was black background with white text with an added blank page at the beginning... so I gave up all together.
(As a result of wasting an entire day guessing at settings trying to get this to work - I write this:
HINT: Your Documentation is missing definitions on what the TiffOptions settings are, as well as just about every other API I sought - your documentation should have a full-time person committed to adding definitions and multiple use examples.)

My workaround result - not using Aspose.Imaging temporarily: The PDF add TIF page code uses the Microsoft converted to G3 1Bpp resized to that of the first set image, and resizes all subsequent pages to that of the defined size (first doc) - and then using Aspose.Objectconverter to export a single multi-paged TIFF from the PDF.

My problems with the workaround that I hope your fix will solve are:
1) Using MS - each converted TIF has random pixels around the converted to dots grayscale image - and I had to write code to parse and examine every single pixel and all surrounding pixels of an 7x7 block of the image using getpixel incrementally to see if any pixels are next to each pixel and white it out if it is surrounded by white... I imagine this will significantly slow the processing time - and hope your solution doesn't generate random pixels - has a better filter for 'noise'.

2) Potential out of memory issues using Microsoft. The Primary reason we wish to use your Aspose.Imaging product is to be able to specify a hard-disk cache instead of memory eventually. Some of the TIF documents we create will have 150-200 pages - so creating them in a disk cache would be greatly helpful.

The sought end-result:
Aspose.Imaging supporting importing and converting any sourced image type to the defined output type - so minor differences in image size is 'rescaled' to the TiffSettings defined size and resolution. The sample code existing and fact you can go from any type to TiffImage implies some form of conversion is present - but it must somehow look at the first image added and use it's settings to resize, set to same compression, etc. all remaining tiff pages - defining them in a TiffOptions could be used if it worked...

A sample solution that will permit importing TIFs into a TiffImage could look something like:
using (TiffImage timage = (TiffImage)Aspose.Imaging.Image.Create(createOptions, ImageCopy.Width, ImageCopy.Height))
RasterImage imageAdd = (RasterImage)Aspose.Imaging.Image.Load(**MemoryStreamOfMultiPageTIFF - or - FilePathToTIFFfile***);
// Create a frameAdd to the TiffImage timage using the defined compression and size settings
TiffFrame frameAdd = TiffFrame.CreateFrameFrom(timage.ActiveFrame, createOptions);
frameAdd.SavePixels(imageAdd.Bounds, imageAdd.LoadPixels(imageAdd.Bounds));
timage.AddFrame(frameAdd);

I hope this additional info helps to narrow down the problems and help find a solution faster - we are in URGENT need of one...

Our company IS purchasing Aspose.Total I am told as another group is already using it for PDF stuff. So please rush this request.


Thank you!
Todd

Hi Todd,


Sorry for the inconvenience faced.

I've shared your concern of urgency with development team and also shared your finding/suggestions for the resolution of issue. As soon as I receive any further news in this regard, I'll post here for your kind reference.

Thanks for your patience and cooperation.


Best Regards,

Thanks Tilal,

We appreciate your help escalating this issue.
We did purchase an Aspose.Total license, and have a major product release in June - so the need to get this coded and working is very urgent.
If you need some help testing I would be glad to help with Beta testing changes...
as I have a QA deadline of May 17th to finish all code changes using your released product.

Summary of use we need Aspose.Imaging product to help with:
Add existing frames from different sources to a single TiffImage (from multi-frame TIF MemoryStream or file sources) of different compression, resolution and size - adjusting them during the add process to the defined compression, resolution and size (using either TiffSettings, or the settings of the first added page to define these specs, either is fine).

This would solve our needs - as the cache to hard disk is the primary reason we need your product as some of the resulting TIFF files we create could have 150 or more approx. 2000x1700 200dpi G4 frames. Currently using MS we often hit out of memory errors.

Thank you again for your assistance,

Todd Nelson
Programmer Analyst II
Univita Health Inc.

Hi Todd,


Thanks for your feedback. I’ve shared your deadlines with the concerns. Our development team is investigating the issue and I’ll update you with our findings/ETA as soon as investigation phase is completed.

Thanks for your cooperation.

Best Regards.

Hi Todd,


Thanks for your patience. Hopefully you can achieve your results by following workaround.

1) Apply required compression setting, convert image to black/white manullay and save to stream or disk as required.

using (TiffImage image = (TiffImage)Aspose.Imaging.Image.Load(myDir + “ReportStreamIn.tif”))
{
Aspose.Imaging.ImageOptions.TiffOptions saveOptions = new Aspose.Imaging.ImageOptions.TiffOptions();
saveOptions.Compression = Aspose.Imaging.FileFormats.Tiff.Enums.TiffCompressions.CcittFax4;
saveOptions.BitsPerSample = 1;
saveOptions.SamplesPerPixel = 1;

for (int ii = 0; ii < image.Frames.Length; ii++)
{
Color[] colors = (image.Frames[ii]).LoadPixels(image.Bounds);
for (int i = 0; i < colors.Length; i++)
{
int power = 200;

if (colors[i].R > power && colors[i].G > power && colors[i].B > power)
{
colors[i] = Color.White;
}
else
{
colors[i] = Color.Black;
}
}

(image.Frames[ii]).SavePixels(image.Bounds, colors);
}
image.Save(myDir + “ReportStreamInCcittFax4.tiff”, saveOptions);

}

2) Concatenate the resultant images and save to stream or disk.

//Create an instance of TiffImage and load existing images
FileStream fileStream1 = new FileStream(myDir + “ReportStreamInCcittFax4.tiff”, FileMode.Open);
FileStream fileStream2 = new FileStream(myDir + “AdditionalTifsCcittFax4.tiff”, FileMode.Open);
TiffImage image1 = (TiffImage)Image.Load(fileStream1);
TiffImage image2 = (TiffImage)Image.Load(fileStream2);
int frameCounter = 0;

//Iterate over the TiffFrames in TiffImage
foreach (TiffFrame tiffFrame in image2.Frames)
{
// Create an instance of TIffFrame and copy active frame of source image
image2.ActiveFrame = tiffFrame;
TiffFrame frame = TiffFrame.CopyFrame(image2.ActiveFrame);
// Add copied frame to destination image
image1.AddFrame(frame);
frameCounter++;

}

// save the image with changes.
image1.Save(fileStream1);


fileStream1.Close();
fileStream2.Close();

Please feel free to contact us for any further assistance.

Best Regards,

I have tried ALL samples found on your forum.

The above will not work - it converts to either white or black - destroying the colored company logo existing on page one of the first TIF added.

My sample code converts to a pixelated grayscale - taking the color image and pixel converting it to a density based grayscale (black dots together = black, further apart = gray)...

Please see the attached color input and expected output images.
I also included the latest working version of code - with modified CopyToB(...) method I used to convert the read TIF file to the correct destination and resolution 'single frame 1bpp user-defined compression TIF' memorystream used in the main function to standardize the images read prior to adding them to the PDF.

5/10 Update: The work-around code using Aspose.PDF SaveToTIFF(..) works using the Aspose.PDF 8.0 release...

I am still hoping to get this Aspose.Imaging issue resolved as we need the ability to cache to HD for large TIFF files.

These samples will not work because:

1) they convert the logo to solid black - destroying it's representation, resulting in a silhouette of the logo and not the copyrighted logo.
The output must be a B&W pixelated grayscale - not either black or white per-pixel conversion. Please see the sample output needed result image file TiffOutput.tif in the attached zip.

2) The concatenating code you provide does not consider adding TIF frames from MemoryStream's of different sizes or resolutions - it needs to convert the added frame to the that of the original. I.e. determine the max width/height of the to be added frame, and resize it to that of the first frame - so all added frames are scaled to fit within the size of the first frame.
I am using the specs of the first TIF loaded and converting the subsequent TIFs to that resolution and size.
In my attempts to use the TiffImage AddFrame method shown in the sample above - which I stated in my posts - attempting to concatenate the second TIF which had slightly different specs causes the AddFrame to fail throwing an exception.
Size differences can be like 1700x2200 for the first TIF, 1728x2263 second TIF, etc.

My fix suggestion - add code inside AddFrame to check and compare the new frame to TiffImage first frame and re-scale it to match the largest height or width of the base source (or to a defined setting assigned in TiffSettings - that way it could be defined/managed externally if you want to manage size externally - would be better if it could be internal to Aspose.Imaging though)
This way - the frame being added fits as large as possible while maintaining the same aspect ratio in the new TIF and is the same resolution, size, and Compression as the base first added frame in the TiffImage - that would solve this problem.

My attempts to use Aspose.Imaging are seen in the commented out TiffImage portions in my attached document.cs file in the .zip file.

Thank you for your assistance -
Todd

Hi Todd,


Thanks for your feedback. I’ve noted the concerns and shared with our development team. We will keep you updated about issue progress via this forum thread.

Moreover in reference to Aspose.Pdf exception, the reported issue has been resolved and fix will be included in coming release of Aspose.Pdf for .NET 8.0. Hopefully it will be released in coming week after completion of testing.

Best Regards,

Hello Aspose,

It has been two weeks - can we get an update?

The workaround we are using DOES fail on larger TIF files, so our need of Aspose.Imaging caching is urgent. Creating a PDF of TIF images just so we can get a single TIF is very time consuming - we really need a faster stable solution.

Guessing this issue is IMAGING-33437 (Unresolved); since it states Unresolved.
The other IMAGING-33458 (Fixed) - what is this?

Thank you,
Todd

Hi Todd,


Thanks for your inquiry. Yes one of your reported issue IMAGING-33458, adding existing frames with different settings in Tiff image, has been resolved and this fix will be included in Aspose.Imaging for .NET 1.8. It would be published in couple days after completion of testing.

Moreover about IMAGING-33437, grayscale Tiff, its not resolved at the moment. You may use the following algorithm as a workaround.


Which gives a similar result to what he requires. We are planning to include dithering in some future Aspose.Imaging versions.

Please feel free to contact us for any further assistance.

Best Regards,



PS: Currently we support CCITT T4 compression and it strictly defines only black and white pixels encoding.

I see it is available - so I downloaded and am trying to use Aspose.Imaging version 1.8.

Apparently the API has changed and there is no sample code anywhere I can see to use it.

Trying to guess at how to add a second set of TIF Frames from a second TIF to the first - where the first is of a different size I am still unable to add them, receiving an exception:{Aspose.Imaging.Exceptions.ImageFormats.TiffImageException: Frame belongs to other image
at Aspose.Imaging.FileFormats.Tiff.TiffImage.AddFrames(TiffFrame[] frames)

I tried creating a Clone copy of the second images frames and add that - same error.

Can you profile a code sample that will approximate the needed process:

1) load a TIF Image initially from a TIF MemoryStream (our sample has 3 - 200dpi G4 images of possibly various sizes)
2) load multiple successive TIF images to add their frames to the first set
a) loop i) and ii) through all frames of each successive TIF to be added to base.
i) Somehow export each frame to a MS Bitmap Image so it can be Dithered and converted it to G4 - 200dpi and original size
ii) Add Dither/resized processed original sized image TIF MemoryStream to base TIF
3) Save that resulting TIF image to a single MemoryStream at 200dpi G4

I tried sample code shown in documentation yet get error as soon as attempt to add frames from second TIF to first original image are attempted.

This is still an urgent issue - your help is appreciated.

Thank you,
Todd Nelson
Univita

Hi Todd,


Thanks for your inquiry. Sorry for the inconvenience we were in process of release publishing. Please check following documentation link for adding frames in TIFF image. Hopefully it will serve the purpose.


Please feel free to contact us for any further assistance.

Best Regards,

The issues you have found earlier (filed as IMAGING-33458) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.