Image Quality Issue when Converting PowerPoint Presentation to TIFF in C#

I won’t to generate black&white .tiff of ppt so, for the black&white print I add compaction TiffCompressionTypes.CCITT4 in Export.TiffOptions but the image quality is very poor

so is there any other way to print black&white with good quality?

My sample code

AsposePpt.Export.TiffOptions options = new AsposePpt.Export.TiffOptions();
options.DpiX = 300;
options.DpiY = 300;
options.CompressionType = AsposePpt.Export.TiffCompressionTypes.CCITT4;
int[] slidIndex = new int[1];
for (int i = 0; i < _document.Slides.Count; i++)
{
    slidIndex[0] = i + 1;
    _document.Save($@"ppt_{i}.tiff", slidIndex, AsposePpt.Export.SaveFormat.Tiff, options);
}

NOTE: PPT and tiff are attached.

PPT tiff issue.zip (117.8 KB)

@hemalp can you please add the PPT file?

tiffGenerationIssue.zip (921.1 KB)

@hemalp thanks for the additional information, I was able to replicate your problem, I’ll escalate this to the development team for further analysis.

Hi ,

any update on above concern ? how we generate quality page output for PPT file ?

@hemalp the issue is still under analysis. As soon as we make a change on the status of the issue you will be notified.
You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

hello @eduardo.canal

any update on this point ?

@hemalp,
I’ve requested an update on the issue from our developers for you. We will let you know soon.

@hemalp,
Please try using the following code example:

using Presentation presentation = new Presentation("input.ppt");
for (int i = 0; i < presentation.Slides.Count; i++)
{
    using Bitmap slide = presentation.Slides[i].GetThumbnail(presentation.SlideSize.Size.ToSize());
    for (int x = 0; x < slide.Width; x++)
    {
        for (int y = 0; y < slide.Height; y++)
        {
            Color pixel = slide.GetPixel(x, y);
            byte gray = (byte)(pixel.GetBrightness() * 255);
            slide.SetPixel(x, y, Color.FromArgb(gray, gray, gray));
        }
    }
    slide.Save($"slide_{i}.tiff", ImageFormat.Tiff);
}

Hello @andrey.potapov

as per your suggestion, an Exception occurs while using the SetPixel method. Please find code sample,

CodeSample:

using (Presentation pres = new Presentation(@"xyz.ppt"))
{
    TiffOptions options = new TiffOptions();
    options.DpiX = 300;
    options.DpiY = 300;
    options.ImageSize = new Size((int)(11 * 300), (int)(8.5 * 300));
    options.CompressionType = TiffCompressionTypes.CCITT4;
    options.ShowHiddenSlides = true;
    pres.SlideSize.SetSize(SlideSizeType.Widescreen, SlideSizeScaleType.EnsureFit);

    for (int i = 0; i < pres.Slides.Count; i++)
    {
        using (Bitmap slide = pres.Slides[i].GetThumbnail(options))
        {
            for (int x = 0; x < slide.Width; x++)
            {
                for (int y = 0; y < slide.Height; y++)
                {
                    Color pixel = slide.GetPixel(x, y);
                    byte gray = (byte)(pixel.GetBrightness() * 255);
                    slide.SetPixel(x, y, Color.FromArgb(gray, gray, gray));
                }
            }
            slide.Save(Path.Combine(@"D:\", $"slide_{i}.tiff"), ImageFormat.Tiff);
        }
    }
}

Thanks

@hemalp,
Please share the following additional files and information:

  • the “xyz.ppt” file
  • OS version on which the code was executed
  • .NET target platform in your app
  • full stack trace of the exception

Hello @andrey.potapov

Please find below your require info

Sample File : samplePPT.zip (107.6 KB)

Os version : Window 10 Enterprise

.NET targeted platform : .NET Framework 4.8

Exception : “SetPixel is not supported for images with indexed pixel formats.”

@hemalp,
The error occurs when you pass the TiffOptions object to the GetThumbnail method. You should pass the image size to the method as follows for example:

using (Bitmap slide = pres.Slides[i].GetThumbnail(pres.SlideSize.Size.ToSize()))
{
    // ...
}

Hello @andrey.potapov

but we compulsory require all the below options to apply,

TiffOptions options = new TiffOptions();
options.DpiX = 300;
options.DpiY = 300;
options.ImageSize = new Size((int)(11 * 300), (int)(8.5 * 300));
options.CompressionType = TiffCompressionTypes.CCITT4;
options.ShowHiddenSlides = true;
pres.SlideSize.SetSize(SlideSizeType.Widescreen, SlideSizeScaleType.EnsureFit);

please give us a solution by applying the tiff option.

@hemalp,
I’ve requested a solution from our developers for you. We will get back to you as soon as possible.

@hemalp,
For using the TiffOptions properties, please try using the following code snippet. Please note that you should choose the grayscaleThreshold value for the best result.

// Adjust the GrayscaleThreshold from 0.01f to 0.99f to get the best result.
// 0.7f looks great.
float grayscaleThreshold = 0.7f;

TiffOptions options = new TiffOptions
{
    DpiX = 300,
    DpiY = 300,
    ImageSize = new Size((int)(11 * 300), (int)(8.5 * 300)),
    // You shouldn't set compression type here.
    //CompressionType = TiffCompressionTypes.CCITT4,
    ShowHiddenSlides = true
};

// Search for the appropriate image encoder for tiff images.
ImageCodecInfo info = null;
foreach (ImageCodecInfo imageCodecInfo in ImageCodecInfo.GetImageEncoders())
{
    if (imageCodecInfo.MimeType.ToLower().Equals("image/tiff"))
        info = imageCodecInfo;
}

if (info != null)
{
    EncoderParameters ep = new EncoderParameters(1);
    // You should set the compression type here.
    ep.Param[0] = new EncoderParameter(Encoder.Compression, (long)EncoderValue.CompressionCCITT4);

    using (Presentation presentation = new Presentation("input.ppt"))
    {
        for (int i = 0; i < presentation.Slides.Count; i++)
        {
            // Convert the slide to an image using the specified options.
            using (Bitmap slide = presentation.Slides[i].GetThumbnail(options))
            {
                for (int x = 0; x < slide.Width; x++)
                {
                    for (int y = 0; y < slide.Height; y++)
                    {
                        // Check the brightness value of the pixel and compare it to the grayscale threshold. 
                        // If the brightness is greater than the threshold, the pixel is set to white; otherwise, it is set to black.
                        slide.SetPixel(x, y, (slide.GetPixel(x, y).GetBrightness() > grayscaleThreshold) ? Color.White : Color.Black);
                    }
                }
                // The modified image is saved as a tiff file using the image encoder and compression parameters.
                slide.Save($"ppt{i}.tiff", info, ep);
            }
        }
    }
}

@andrey.potapov

Provided Solution Not working.
image.png (37.7 KB)

Required Files: Embedded Bluetooth.zip (107.6 KB)

@hemalp,
Unfortunately, I was unable to reproduce the exception you mentioned. output.zip (40.4 KB).
Please test the code example above without any changes. If the issue persists, please share additional information about your environment to reproduce the error.

@andrey.potapov
It is Working Now, The issue Is I am applying Compression in Option As well as EncoderParameter.

Thanks

@andrey.potapov

The issue with using the suggested Method Is timing. It Takes So much time to generate Images.
So Can you provide Any solution which will not impact the time.