Slides. Image scale

On the attached picture you may find image, inserted in slide.
Scale - height and width is always set to 133 %.
How programmatically (C#) I can set scale to 100% ?

Thanks in advance.

I’m attaching slide (just in case)

Hi Alex,

I have observed that you have made the similar inquiry in past as well over this link:
https://forum.aspose.com/t/picture-scale-size-in-the-slide/72287
Can you please share the source image with us that you are trying to embed in your presentation so that I may be able to carry my investigation further. For normal image on my side, I am not getting the issue shared by you.

Many Thanks,

Hi Mudassir,
I attached power-point with image as you requested.

Method which builds slide with image:

private void AddPicture(SlideEx slide, MemoryStream ChartStream, float coordinateX, float coordinateY)
{
if (ChartStream == null)
{
return;
}

System.Drawing.Image img = (System.Drawing.Image)new Bitmap(ChartStream);
ImageEx imgx = presentation.Images.AddImage(img);
slide.Shapes.AddPictureFrame(ShapeTypeEx.Rectangle, coordinateX, coordinateY, imgx.Width, imgx.Height, imgx);
}

So, I’m not using File (image) to put in slide, I’m using MemoryStream object.
In my similar request (about which I forgot that have created), you said that possible reason could be that size of picture frame is bigger than image size. But I don’t know how to change picture frame size.

Hi Alex,


I have worked with the source presentation shared by and extracted the image from it using PowerPoint and saving that as file. Then I used Aspose.Slides to add that image in my slide and there was no issue. I used following sample code and for your kind reference, I have attached the generated presentation as well.

public static void addPicFrame()
{
//Instantiate PrseetationEx class that represents the PPTX
PresentationEx pres = new PresentationEx();

//Get the first slide
SlideEx sld = pres.Slides[0];

//Instantiate the ImageEx class
System.Drawing.Image img = (System.Drawing.Image)new Bitmap(“d:\Aspose Data\Picture1.png”);
ImageEx imgx = pres.Images.AddImage(img);

//Add Picture Frame with height and width equivalent of Picture
int id=sld.Shapes.AddPictureFrame(ShapeTypeEx.Rectangle, 50, 50, imgx.Width, imgx.Height, imgx);
//Write the PPTX file to disk
pres.Write(“d:\Aspose Data\RectPicFrame.pptx”);
}


With picture extracted from your presentation, things are fine on my end. I need the source image that is available in the form of memory stream. You can save that image to disk and share with us. Please also share the source of the image that you are trying to embed in PowerPoint slide.

Secondly, I have created an issue with ID SLIDESNET-34419 as new feature request to further investigate the possibility of providing support for setting image scale options. I have also linked this thread with issue so that you may be automatically notified once the issue will be resolved.

Many Thanks,

Hi Mudassir

Please use attached file for reproducting my case.
That file is serialized MemoryStream object (I prepared it from my application speccially for this my request)
You may deserialize it like that:

MemoryStream ms = new MemoryStream();
FileStream file = new FileStream("MemoryStream.bin", FileMode.Open, FileAccess.Read);
byte[] bytes = new byte[file.Length];
file.Read(bytes, 0, (int)file.Length);
ms.Write(bytes, 0, (int)file.Length);
file.Close();
ms.Close();

Thanks

Hi Alex,

Thanks for sharing the further information. I have tried to access the file shared using the sample code shared by you. I have obtained ArgumentException when reading the memory stream in Image call object. Can you please verify the issue on your end by using the following sample and kindly share the working file.

public static void addPicFrame()
{
//Instantiate PrseetationEx class that represents the PPTX
PresentationEx pres = new PresentationEx();

//Get the first slide
SlideEx sld = pres.Slides[0];

float centerX = pres.SlideSize.Size.Width/2;
float centerY = pres.SlideSize.Size.Height/2;

String imagePath=@"D:\Aspose Data\MemoryStream\";

MemoryStream ms = new MemoryStream();
FileStream file = new FileStream(imagePath+"MemoryStream.bin", FileMode.Open, FileAccess.Read);
byte[] bytes = new byte[file.Length];
file.Read(bytes, 0, (int)file.Length);
ms.Write(bytes, 0, (int)file.Length);
file.Close();
ms.Position = 0;

System.Drawing.Image img = (System.Drawing.Image)new Bitmap(ms);
ms.Close();
//Instantiate the ImageEx class
// System.Drawing.Image img = (System.Drawing.Image)new Bitmap("d:\\Aspose Data\\Picture1.png");
ImageEx imgx = pres.Images.AddImage(img);

float imagePosX = centerX - (imgx.Width/2);
float imagePosY = centerY - (imgx.Height/2);

//Add Picture Frame with height and width equivalent of Picture
int id=sld.Shapes.AddPictureFrame(ShapeTypeEx.Rectangle, 50, 50, imgx.Width, imgx.Height, imgx);
PictureFrameEx picfram = (PictureFrameEx)sld.Shapes[id];
//Write the PPTX file to disk
pres.Write("d:\\Aspose Data\\RectPicFrame.pptx");
}

Many Thanks,

I have the same problem with the following base64 encoded image:


iVBORw0K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MV3TOmm2DlKs6bXfEvMeQbVJp73mD2z88x5BtVmDKW/RSzfNMKo2Zu4l0YJfsUKBi48i/NE306lKZHNGc/Ms3VPjWKEzqf1nh0gkl+qhQe0bXlM/QII37qlE7qOOgdP8mAn05TquMfnzL9FtFJyTmpcvAfOunQ7dOsdErV1O/oKZJPveKEivOeGWb4dihOT8kd/YemponeHoXREVmTv/ERNnJtUyhNSMh/fGSiRPQ2Kuc/O5kg+clZkrdZ6YW5+Zk4A8D4zPzcC0zvrVcozJ2aHRM/+Vsamz01V6DLx5KrqH90qn9MvyLHeXzOefHU8ZnJp7rG/tTkzPFTLzpzj5t+ufbKeT7L1T+kwn96HnMue+m5J4/PziyMjU2ODw/3Dg+PT46NLczMHn/yuZcuc174L78XJ5mc95NcerJ3Xn7F9CvIvtp47zR/***/isvm34FK0POCWbfkwL/M9YeK4ov/Fxq+j5Uqwe/nH2KRn6oVrvmL4/69HwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAICM+D/j3fNlSGtFLgAAAABJRU5ErkJggg==

You can use this code to decode:
			var lImage = Convert.FromBase64String(base64);
		<span style="color:green;">// Get memory stream to image.</span>
		<span style="color:blue;">var</span> ms = <span style="color:blue;">new</span> <span style="color:#2b91af;">MemoryStream</span>(lImage); <span style="color:green;">// We don't dispose this stream because of the remarks here : http://msdn.microsoft.com/en-us/library/93z9ee4x.aspx (ImageEx seems to cerate an Image object too)</span>

			ImageEx imgx = lPres.Images.AddImage(ms);
I do not notice any exceptions being throw while debugging with CLR exceptions captured.
Any workarounds would be welcome.
Multiplying with 0.7518796992481f both dimensions seems to solve the problem for this image, but I don’t know if all images are scaled the same.

Kostas

Hi Kostas,

I like to share that an issue with ID SLIDESNET-34419 has been created as new feature request to provide the image scaling options for picture frame or other shapes in Aspose.Slides as given in very first post of this slide. Once the properties will be available they can be used to set the image width or height in percentages w.r.t actual image width or height.

Many Thanks,

Hi Alex,

I like to share that we have introduced the support for setting the RelativeScaleHeight and RelativeScaleWidth in Aspose.Slides for .NET 7.9.0. Please try using the following sample code on your end to serve the purpose.


PresentationEx pres = new PresentationEx(Path.Combine(“34419.pptx”));
PictureFrameEx pf = pres.Slides[0].Shapes[0] as PictureFrameEx;
pf.RelativeScaleHeight = 0.8f;
pf.RelativeScaleWidth = 1.35f;
pres.Write(“34419 out.pptx”);

I will share the product notification with you shortly.

Many Thanks,

The issues you have found earlier (filed as SLIDESNET-34419) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.

Thanks for notification.