Inserting jpg in cropped PictureFrameEx object

I am trying to create pptx presentations from info in a database. This is working well. On some of the pages, I load a jpg file into a PictureFrameEx. This works well, too. The mod that I would like to have is to have a PictureFrameEx, that already contains crop info, into which I can drop a jpg.

I took a page from another pptx, which does the cropping, to use as a template. When I dropped the new jpg into the template (oPic.PictureFormat.Picture.Image = oImageEx), the old file remained and it looked like the new image was behind it. It seemed like the cropped image was somewhere else in the PictureFrameEx structure. Is it?

Any help would be appreciated. I have attached the template which I would like to use.

Thanks

More info on this issue.

I am tring to use the CropBottom feature of the PictureFormat:

Dim oArt As System.Drawing.Image
Dim oPic As PictureFrameEx
Dim oImageEx As ImageEx

oPic = CType(oSlide.FindShapeByAltText(***), PictureFrameEx)
oArt = PPTx.loadImageFromFile(sFile)
oImageEx = oPres.Images.AddImage(oArt)
PPTx.adjustPicFrameForArt(oPic, oImageEx)
oPic.PictureFormat.Picture.Image = oImageEx
oPic.PictureFormat.CropBottom = 0.0
oArt.Dispose()

If I use the next to last line to CropBottom, no image even is displayed. Instead, I get the message - 'The image cannot be displayed. Your computer may not have enough memory...' If I comment the line out, the image displays (but is not cropped, of course).

What am I doing wrong? (It would be nicer still if the cropping was already in the PictureFrameEx and I could drop a picture into it without having to do the cropping in code; maybe).

Thanks

PS. Regardless of how I create the pptx files, an error occurs when reading them in PowerPoint. It says 'PowerPoint found unreadable content in CreatePPTx.pptx. Do you want to recover the contents...' Is this a common problem? Any clues on fixing the pptx creation to make it readable? I answer yes to PowerPoint to have it fix the problem and the file does display correctly.

Hi Brad,

I am sorry for the delayed response but I was working on your specified problem. Below please find the code snippet that I have written for changing the image in a picture frame and it retained the properties of cropping as in source presentation file. For your kind reference, I have also shared the generated presentation file as well.

Dim fPPTPath As String = "D:\\ppt\\"

'Get the Ptah of the pPt saved in Report folder

Dim PPTFullPath As String = fPPTPath + "CroppedTemplatePage.pptx"

'Open the PPT

Dim presnew As PresentationEx = New PresentationEx(PPTFullPath)

'loop through all Slides to replace all images which have Alt Text

For Each slide As SlideEx In presnew.Slides

For Each shape As Aspose.Slides.Pptx.ShapeEx In slide.Shapes

'check if the shape is Picture

If TypeOf shape Is PictureFrameEx Then

Dim pic As PictureFrameEx = CType(shape, PictureFrameEx)

If pic.AlternativeText = "Art" Then

'get d absolute path of newpic

Dim str As String = fPPTPath + "Winter.jpg"

If File.Exists(str) Then

'Adding Image to Picture frame

Dim img As System.Drawing.Image = CType(New Bitmap(str), System.Drawing.Image)

Dim imgx As ImageEx = pic.Presentation.Images.AddImage(img)

pic.PictureFormat.Picture.Image = imgx

End If 'File exists

End If 'Checking Alternative text

End If 'checking picture frame

Next 'Shapes

Next 'Slides

' //Save the modified PPT

Dim output_file_name As String = fPPTPath + "TestImgCrop.pptx"

presnew.Write(output_file_name)

Thanks and Regards,

Hi Muddasir,

Thanks for your help. It looks from your code like you are trying to put the image 'winter.jpg' into the pptx file's 'Art' PictureFrameEx. That is exactly what I am trying to do, too. I assume that the file you sent me (TestImgCrop.pptx) was supposed to be the successful example of doing that.

When I open the file here, I still see the picture as shown in the attached jpg. Are we seeing two different things? If so, do you have a guess as to what is different? As mentioned in a previous post, I am getting errors when trying to open all pptxs that are created with aspose (TestImgCrop.pptx does not cause that problem, though!).

Mudassir,

One possibility as to the problem. When the template was created, the image was 'Imported and Linked'. Is it possible that the old image is being relinked into the slide after we replace it? If so, how does one eliminate that link?

I will try tomorrow to create a template without the link and see if that works.

Brad

HI Brad,

I have seen the issue shared in the attached image file. As I have mentioned earlier that the TestImgCrop.pptx has been generated by the shared code snippet and I am successfully able to open the file with the changed image. For your kind reference, I have attached the print screen image of the generated image. I am using Aspose.Slides for .NET 4.1.1 and using PowerPoint 2007. Please share your further findings if you still feel any problem after using the mentioned version of Aspose.Slides for .NET.

Thanks and Regards,

Hi Mudassir,

As mentioned in my last post, I tried to make a cropped PictureFrame without linking the file. That was the answer! It works just fine as long as the picture in the template is not linked.

Thanks for all your help.

Brad

Hi Mudassir,

I have returned to trying to use the CropBottom property of PictureFormat. I am triggering the cropping based on the aspect ratio of the image:

If fAR < 1.44 Then

oPic.PictureFormat.CropBottom = 0.123245

End If

The pictures which have fAR < 1.44 do not appear at all, the others display correctly. Have I done something wrong or is there a problem with the cropping? Does the cropping factor need to be applied before the image is attached?

Brad

Hi Brad,

I have tried to work on the problem you are encountering. Actually, I have observed an inconsistency in setting the CropBottom property in Aspose.Slides for .NET. An issue with ID 18291 has been created in our issue tracking system to further investigate and resolve the issue. This thread has also been linked with the issue, so that you may be automatically notified, once the issue is resolved.

We are sorry for your inconvenience,