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);
}
@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.
@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);
}
@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()))
{
// ...
}
@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);
}
}
}
}
@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.
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.