We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Insert Image from Database

I need to insert an image from a database into Aspose slides. I found a Java example below but I need a VB version of the same.

'Java Version

Presentation pres = new Presentation();
//Get the first slide
ISlide sld = pres.getSlides().get_Item(0);
//Instantiate the Image class
IPPImage imgx =null;
//In database, image is stored as byte array so instead of file stream, it needs to be written as ByteArrayInputStream
imgx = pres.getImages().addImage( new ByteArrayInputStream(PASS_IMAGE_BYTEARRAY));
//Add Picture Frame with height and width equivalent of Picture
sld.getShapes().addPictureFrame(ShapeType.Rectangle, 50, 150, imgx.getWidth(), imgx.getHeight(), imgx);
//Write the PPTX file to disk
pres.save("ImgDB.pptx", SaveFormat.Pptx);

Hi,


Thank you for your interest in Aspose.Slides.

I have observed your comments and like to share with you that, image is stored as blob (byte array) in the database, so you need to use the MemoryStream and passing the byteArray(blob image data) to its constructor.

Please try using the following sample code and replace the red marked with byte array image data.

Presentation pres = new Presentation();
//Get the first slide
ISlide sld = pres.Slides[0];
//Instantiate the Image class
IPPImage imgx =null;
//In database, image is stored as byte array so instead of file stream, it needs to be written as ByteArrayInputStream
imgx = pres.Images.AddImage( new MemoryStream(PASS_IMAGE_BYTEARRAY));
//Add Picture Frame with height and width equivalent of Picture
sld.Shapes.AddPictureFrame(ShapeType.Rectangle, 50, 150, imgx.Width, imgx.Height, imgx);
//Write the PPTX file to disk
pres.Save(“ImgDB.pptx”, SaveFormat.Pptx);

I hope this will be helpful. Please share if I may help you further in this regard.

Best Regards,

Thank you so much for your help! It worked. Now, I have another problem. I am having trouble deleting predefined text - Click to edit Master Title Styles and Click to edit Title Styles that appear by default on the slides. I am coding in VB .Net. Any help in this regard will be much appreciated.

I get the following error when the value of 'i' is more than 10.

Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index

Below is the code snippet:

Using pres As Presentation = New Presentation()

'Instantiate slide
Dim sld As ISlide = pres.Slides.AddEmptySlide(pres.LayoutSlides.GetByType(SlideLayoutType.TitleAndObject))


'Instantiate SlideCollection class
Dim slds As ISlideCollection = pres.Slides
For i = 0 To dt.Rows.Count - 1

slds.AddEmptySlide(pres.LayoutSlides(i))

'Get the slide
sld = DirectCast(pres.Slides(i), ISlide)

'Add an AutoShape of Rectangle type
Dim ashp As IAutoShape = sld.Shapes.AddAutoShape(ShapeType.Rectangle, 75, 475, 575, 50)
ashp.TextFrame.Paragraphs(0).Portions(0).Text = ""

'Accessing the text frame
Dim txtFrame As ITextFrame = ashp.TextFrame

'Create the Paragraph object for text frame
Dim para As IParagraph = txtFrame.Paragraphs(0)

'Create Portion object for paragraph
Dim portion As IPortion = para.Portions(0)

'Set Text
portion.Text = dt.Rows(i).Item(0)

Next

'Save ppt file

End Using

Hi,


Thank you for getting back to us.

I have replied to your issue of replacing text over this thread, posted by you. I request you to please make a separate post for every single issue you face so that we may try to help you out efficiently.

Regarding the issue of Index was out of range, pasting the code is not enough owing to reason that there are few dependencies like, dt.Rows.Count so please share with us a sample application to reproduce the issue.

Best Regards,