Hi Team,
Aspose Version: 20.1
Language: C#
Issue: We are exporting all the shapes and text in images using Aspose slides API but the exported text also includes the border of the text box.
Code:
public void ExportImages(String outputDirectory) {
//m_Presentation - pptx object
foreach (var curMaster in m_Presentation.Masters) {
foreach (var curShape in curMaster.Shapes) {
Guid curId; // random image name
using (var curImage = curShape.ToBitmap())
{
target.Save(outputDirectory, System.Drawing.Imaging.ImageFormat.Png);
target.Dispose();
}
}
}
}
public static Bitmap ToBitmap(this IShape shape){
return shape.GetThumbnail(ShapeThumbnailBounds.Slide, 1,1);
}
sample.zip (82.8 KB)
Can you share your thoughts?
~ Praveen
@pradubey,
Thank you for your query. Unfortunately, I cannot use the code example you provided (target
is unknown symbol). I used a code example as following and found no errors you described with Aspose.Slides 20.1 and 21.4:
using (var presentation = new Presentation(dataPath + "sample.pptx"))
{
for (int i = 0; i < presentation.Masters.Count; i++)
{
var master = presentation.Masters[i];
for (int j = 0; j < master.Shapes.Count; j++)
{
var shape = master.Shapes[j];
using (var image = shape.GetThumbnail(ShapeThumbnailBounds.Slide, 1, 1))
{
var filePath = dataPath + $"master_{i}_shape_{j}.png";
image.Save(filePath, ImageFormat.Png);
}
}
}
}
Output:
master_0_shape_0.png (2.5 KB)
master_0_shape_1.png (12.8 KB)
master_0_shape_2.png (221 Bytes)
master_1_shape_0.png (633 Bytes)
master_1_shape_1.png (3.7 KB)
Please use the latest version of Aspose.Slides. If the issue persists, please share the comprehensive code snippet reproducing the issue.
Hi @Andrey_Potapov
I should have mentioned it in the initial thread but missed it.
We are creating images from the paragraphs available in the shapes
PPTX -> Slides -> shapes -> paragraphs -> image
Sample code
using (var presentation = new Presentation(m_szPptxPath))
{
for (int i = 0; i < presentation.Slides.Count; i++)
{
var slides = presentation.Slides[i];
for (int j = 0; j < slides.Shapes.Count; j++)
{
var shape = slides.Shapes[j];
var curAutoShape = shape as AutoShape;
using (var cloneShapeImage = curAutoShape.ToBitmap())
{
foreach (var curPara in curAutoShape.TextFrame.Paragraphs)
{
var paraRect = curPara.GetRect();
Rectangle finalRect = new Rectangle();
finalRect.X = (int)(curAutoShape.X);
finalRect.Y = (int)(curAutoShape.Y + paraRect.Y);
finalRect.Width = Math.Max(1, (int)(curAutoShape.Width));
finalRect.Height = Math.Max(1, (int)(paraRect.Height));
ImageUtils.subImage(cloneShapeImage, finalRect).Save("./input/testaspose.png");
}
}
}
}
}
Output image of a paragraph also include the borders
testaspose.png (1.6 KB)
PPTX
sample.zip (80.6 KB)
Please share your thoughts
~ Praveen
@pradubey,
Unfortunately, I cannot use your new code example to reproduce the issue because ImageUtils.subImage
is an unknown part. But I have some thoughts about the issue. If you save cloneShapeImage
to a file, you will get the image with borders: shape.png (1.8 KB). I suppose your finalRect
includes the left border of the shape:
finalRect.X = (int)(curAutoShape.X);
Therefore, you have the left border in the paragraph image. Please check it carefully.
1 Like