I am handling various image types embedded into Powerpoint files. For my code to function properly I need to know the exact dimensions of the embdedded image.
For that purpose I seem to have a multitude of Aspose APIs at my disposal to determine the image dimensions, however these APIs report inconsistent numbers for wmf vector images.
All three seem to report the same dimensions for e.g: jpeg and emf files however for wmf files
the former two seem to report the same dimensions but Aspose.Imaging API report completely different numbers.
Can you please help me clarify this?
I’ve tried it on windows platform with Aspose.Imaging 21.11 and Aspose.Slides 21.11
I have implemented an example solution to demonstrate this.
Please find it attached.
@zpopswat,
Thank you for the additional information. I have reproduced the problem with the image dimensions and added a ticket with ID SLIDESNET-42943 in our issue tracking system. Our development team will investigate this case. You will be notified when the issue is resolved.
@zpopswat,
Our development team investigated the issue. Aspose.Slides API in this part relies on the .NET System.Drawing.Imaging.Metafile implementation. So by using a raw .NET implementation result will be the same as via Slides API in this case:
System.Drawing.Imaging.Metafile metafile = new Metafile("image1.wmf");
Console.WriteLine($"\tSystem.Drawing.Imaging.Metafile size\tHeight[{metafile.Height}]\tWidth[{metafile.Width}]");
@Andrey_Potapov
We’ve reviewed the issue and found, that after saving to disk outputBin1.zip (189.2 KB)
of the slide with wmf file using following code snippet :
@zpopswat,
Thank you for your patience. Our developers have investigated the case. To get the same result in Aspose.Imaging, you can use the WmfImage.FrameBounds property. The following code example shows you how to do this:
using (var presentation = new Presentation("emf_wmf_jpg.pptx"))
{
foreach (var slide in presentation.Slides)
{
foreach (var shape in slide.Shapes)
{
if (shape is PictureFrame pictureFrame && null != pictureFrame.PictureFormat.Picture.Image)
{
IPPImage ippimage = pictureFrame.PictureFormat.Picture.Image;
Console.WriteLine(
$"Image detected on slide[{slide.SlideNumber}]. Image type {ippimage.SystemImage.RawFormat}");
Console.WriteLine(
$"\tIPPImage size\t\t\tHeight[{ippimage.Height}]\tWidth[{ippimage.Width}]");
Console.WriteLine(
$"\tIPPImage.SystemImage size\tHeight[{ippimage.SystemImage.Height}]\tWidth[{ippimage.SystemImage.Width}]");
var imageStream = new MemoryStream(ippimage.BinaryData);
using (Image image = Image.Load(imageStream))
{
if (image is RasterImage rasterImage)
{
Console.WriteLine(
$"\tRasterImage size\t\tHeight[{rasterImage.Height}]\tWidth[{rasterImage.Width}]\ttype[{rasterImage.FileFormat}]");
if (!rasterImage.IsCached)
{
rasterImage.CacheData();
}
}
else if (image is MetaImage metaImage)
{
if (image is WmfImage wmfImage)
{
Console.WriteLine(
$"\tWmfImage size\t\tHeight[{wmfImage.FrameBounds.Height}]\tWidth[{wmfImage.FrameBounds.Width}]\ttype[{metaImage.FileFormat}]");
}
else
{
Console.WriteLine(
$"\tMetaImage size\t\t\tHeight[{metaImage.Height}]\tWidth[{metaImage.Width}]\ttype[{metaImage.FileFormat}]");
}
if (!metaImage.IsCached)
{
metaImage.CacheData();
}
}
}
}
Console.WriteLine();
}
}
}