Bitmap "out of memory" exception

I am using Slides to automatically generate PPTx (just trial version at the moment).

For a large number of slides (150) I am getting an "Out of Memory" exception. I have debugged this down to the fact that the images that are being included are being read into a System.Drawing.Bitmap which is creating a bitmap out of the jpg. I think PPTx can contain the image as a jpg (without ballooning to a bitmap). Can one load the image as a jpg into the Picture?

Currently used code to create an ImageEx:

oFS = New FileStream(sFilePath, FileMode.Open, FileAccess.Read)

oBR = New BinaryReader(oFS)

iLen = New FileInfo(sFilePath).Length

oBA = oBR.ReadBytes(iLen)

oMS = New MemoryStream(oBA)

oImg = System.Drawing.Bitmap.FromStream(oMS)

oImageEx = oPres.Images.AddImage(oImg)

oPic.PictureFormat.Picture.Image = oImageEx

Hi Brad,

Thanks for considering Aspose.Slides.

Yes, you can add image as jpg fie in a PPTX file. Please follow this thread link to see how jpg image has been added in ImageEx object.

Thanks and Regards,

Thanks for your quick reply.

Yes, I am already loading jpg files using that technique. The problem is that when the jpg is read into the Bitmap, it is converted to a bitmap. This takes what was a 2M file and turns it into a 40M bitmap image. This ultimately (with about 70 images) causes the "Out of Memory" exception.

What I would like to be able to do (and I think PPTx does support it) is to load the jpg information (as a jpg) into the PPTx and never have it converted to a Bitmap.

How would one do that?

Mudassir,

Have investigated more without a solution. The problem is that when the Image is created (System.Drawing.Image) from a jpg stream, the Image object takes about 10 times the size of the jpg file. Don't know why that happens, but a hundred or so of those Images will blow up the memory. Is there another way (perhaps just linking the jpg file) that does not require creating and storing Image and ImageEx?

Thanks,

Brad

Hi Brad,

Unfortunately, there is no way available that can only link to a jpg file and not storing that in memory. However, I can suggest you using Aspose.Slides for .NET API compiled for x64 bit, that has been developed to overcome the strict memory limitation issues. Please check the attached Aspose.Slides version for x64 bit and try to use real 64 bit environment. You may try OutOfMemory exception problem on your end and it may help you.

Thanks and Regards,

Sorry to hear that; guess we will bite the bullet and try to go to x64 bit mode.