I get an error when I add a png image to a slide.
Error: Input parameter incorrect
Does slides accept png format?
Thanks
I get an error when I add a png image to a slide.
Error: Input parameter incorrect
Does slides accept png format?
Thanks
At first, I’d like to know what version of Aspose.Slides you use. Java or .Net?
Also please provide example how you add png image.
Thanks for the reply. I am using asp.net. Here is the code. The same thing with .bmp works...
Code:
Dim pres As Presentation = New Presentation
'Adding an empty slide to the presentation and getting the reference of
'that empty slide
Dim slide As Slide = pres.AddEmptySlide()
'Adding a rectangle (X=2400, Y=1800, Width=1000 & Height=500) to the slide
Dim rect As Aspose.Slides.Rectangle = slide.Shapes.AddRectangle(2400, 1800, 1000, 500)
'Hiding the lines of rectangle
rect.LineFormat.ShowLines = False
'Adding a text frame to the rectangle with "Hello World" as a default text
rect.AddTextFrame("Hello World")
'Removing the first slide of the presentation which is always added by
'Aspose.Slides by default while creating the presentation
pres.Slides.RemoveAt(0)
pres.AddEmptySlide()
pres.AddEmptySlide()
'Accessing a slide using its slide position
Dim slide2 As Slide = pres.GetSlideByPosition(2)
'Creating a picture object that will be used to fill the ellipse
Dim pic As Picture = New Picture(pres, "C:\\BarChart.png")
'Adding the picture object to pictures collection of the presentation
'After the picture object is added, the picture is given a uniqe picture Id
Dim picId As Integer = pres.Pictures.Add(pic)
'Calculating picture width and height
Dim pictureWidth As Integer = pres.Pictures(picId - 1).Image.Width * 4
Dim pictureHeight As Integer = pres.Pictures(picId - 1).Image.Height * 4
'Calculating slide width and height
Dim slideWidth As Integer = slide2.Background.Width
Dim slideHeight As Integer = slide2.Background.Height
'Calculating the width and height of picture frame
Dim pictureFrameWidth As Integer = Convert.ToInt32(slideWidth / 2 - pictureWidth / 2)
Dim pictureFrameHeight As Integer = Convert.ToInt32(slideHeight / 2 - pictureHeight / 2)
'Adding picture frame to the slide
slide2.Shapes.AddPictureFrame(picId, pictureFrameWidth, pictureFrameHeight, pictureWidth, pictureHeight)
'Writing the presentation as a PPT file
pres.Write("C:\\hello.ppt")
Code looks good. Probably .Net runtime can’t open your .png file. Try to open it with
standard System.Drawing.Bitmap class and check if you have the same exception.
It works fine with the bmp class.
Any ideas…
Thanks
Why you think this problem is because of png image? Are you sure exception thrown when you load image?
I don’t see any useful information in the error message you posted.
Please provide fill error message with stacktrace and line numbers where exception was thrown.
Always use pres.Slides.Remove(pres.GetSlidesByPosition(1)) instead of pres.Slides.RemoveAt(0)
Code pres.Pictures(picId - 1) is wrong. You should use pres.Pictures.GetPictureById(picId).
Here is the stack trace and exception message. The above code is the one found in the documentation
to create a hello world ppt.
Thanks,
Invalid parameter used.
Description:
An unhandled exception occurred during the execution of the current web
request. Please review the stack trace for more information about the error and
where it originated in the code.
Exception Details:
System.ArgumentException: Invalid parameter used.
Source
Error:
Line 73: |
[ArgumentException: Invalid parameter used.] |
Aspose.Slides uses this code to open image:
FileStream fs = new FileStream(file, FileMode.Open, FileAccess.Read);
Image img = Image.FromStream(stream);
As you see in the stacktrace exception thrown inside .net framework when it try to load image.
So it’s not a problem of Aspose.Slides.
Just for information. Image.FromStream() and Bitmap() constructor use absolutely the same code
to load images with only one difference. Image.FromStream validates image before loading and
check if it has any broken data.