Picture and chart to image feature

Hi,

I was wondering if you can create a function that can convert the pictures and charts in excel to tiff image with compression. I know that you have the sheet2imagebypage function but I need to extract the charts and images individually and have it compressed. Please help. thank you.

Hi,

The Tiff compressions are supported in Chart - to - Image feature, see the following sample code.

Workbook workbook = new Workbook();
workbook.Open(“e:\test\Aspose.xlsx”);
Worksheet worksheet = workbook.Worksheets[0];
Chart chart = worksheet.Charts[0];

//Apply different Image and Print options
ImageOrPrintOptions options = new ImageOrPrintOptions();
//Set Horizontal Resolution
options.HorizontalResolution = 200;
//Set Vertical Resolution
options.VerticalResolution = 200;
//Set TiffCompression
options.TiffCompression = TiffCompression.CompressionLZW;
//Set Image Format
options.ImageFormat = System.Drawing.Imaging.ImageFormat.Tiff;


//Convert chart to image.
System.Drawing.Bitmap img = chart.ToImage(options);

//Save image file
img.Save(@“e:\test\outChartImage.tiff”, System.Drawing.Imaging.ImageFormat.Tiff);

For extracting images in the sheet in Tiff compression is not supported. We have added your feature request into our issue tracking system with an issue id: CELLSNET-13893. We will soon look into your feature.

Thank you.

Hi,

Well, we think you can get the image data with Picture.Data by yourself,
then convert the data to Tiff file with the following SaveTiff method:<o:p></o:p>

Sample code:


public static ImageCodecInfo GetEncoderInfo(string mimeType)

{

ImageCodecInfo[] codecs = ImageCodecInfo.GetImageEncoders();

for (int i = 0; i < codecs.Length; i++)

if (codecs[i].MimeType == mimeType)

return codecs[i];

return null;

}

internal static void SaveTiff(byte[] imageData,

ImageOrPrintOptions options, string imageFile)

{

Image image = Image.FromStream(new MemoryStream(imageData));

ImageCodecInfo imageCodecInfo;

Encoder encoder;

EncoderParameter encoderParameter;

EncoderParameters encoderParameters;

EncoderValue encoderValue = EncoderValue.CompressionLZW;

bool isToBitonal = false;

switch (options.TiffCompression)

{

case TiffCompression.CompressionNone:

encoderValue = EncoderValue.CompressionNone;

break;

case TiffCompression.CompressionRle:

isToBitonal = true;

encoderValue = EncoderValue.CompressionRle;

break;

case TiffCompression.CompressionCCITT3:

isToBitonal = true;

encoderValue = EncoderValue.CompressionCCITT3;

break;

case TiffCompression.CompressionCCITT4:

isToBitonal = true;

encoderValue = EncoderValue.CompressionCCITT4;

break;

default:

encoderValue = EncoderValue.CompressionLZW;

break;

}

Image dest = null;

//if (!isToBitonal)

//{

// dest = SetResolution(image, options);

//}

//else

//{

// Image destSetDpi = SetResolution(image, options);

// dest = ConvertToBitonal(destSetDpi, options);

//}

// Get an ImageCodecInfo object that represents the TIFF codec.

imageCodecInfo = GetEncoderInfo("image/tiff");

// Create an Encoder object based on the GUID

// for the Compression parameter category.

encoder = Encoder.Compression;

// Create an EncoderParameters object.

// An EncoderParameters object has an array of EncoderParameter

// objects. In this case, there is only one

// EncoderParameter object in the array.

encoderParameters = new EncoderParameters(1);

// Save the bitmap as a TIFF file with LZW compression.

encoderParameter = new EncoderParameter(encoder, (long)encoderValue);

encoderParameters.Param[0] = encoderParameter;

//if (stream != null)

//{

// dest.Save(stream, imageCodecInfo, encoderParameters);

//}

//else

{

dest.Save(imageFile, imageCodecInfo, encoderParameters);

}

dest.Dispose();

}


Thank you.

Hi, Can you provide me the functions: SetResolution(image,
options) and
ConvertToBitonal(destSetDpi, options). You commented out the code that assigns value to
Image dest = null; so dest is never assigned. thank you.



// Image destSetDpi = SetResolution(image,
options);<o:p></o:p>

// dest = ConvertToBitonal(destSetDpi, options);


Hi,

Does the code(un-commented sample code) mentioned in my previous post not fulfill your general requirement?

Anyways, we will check if we can provide you the SetResolution(image,
options) and
ConvertToBitonal(destSetDpi, options) code segments for your requirement. We will get back to you soon.

Thank you.

The previous code doesn’t assign a value to
Image dest = null; So I can’t make the conversion using the save function. I would need to have SetResolution() and ConvertToBitonal() to get it working. Also, does the code that you provide resize the image to legal paper size of 8’5 by 11? If not, how do you resize it? Thank you.

Hi, Have you check to see if you can provide me those 2 functions? If not, can you please help me create a function in Aspose cell to extract the pictures and resize them to a give dimension. Thank you.

Hi,

Please find attached the zipped archive that contains the source codes and other files for your requirement.

Thank you.

Hi,

Please try the attached version. We have supported and enhanced ToImage for Shape.

Thank you.