Retrieve image attributes from slide

Hello,

I am trying to retrieve the attribute of the images present on the PPT.
I am able to read the images in the byte array from the presentation object.
following is my code code

def pic = pres.getPictures();
byte[] b = null;
b = pic.get(0).getImage()

But I am not able to retrieve the height, width, x and y co-ordinate of the image by using this method.

I am able to retrieve it(height, width, x, y) from the shape object.

So please tell me if there is any way to find height, width, x, y of the image by first method(by using presentation object) OR is there any relation between the images getting from presentation object and the shape object.

Thanks-
Rahul

Dear Rahul,

There are two ways to extract the image from the slide. One way is to use Presentation.getPictures().get(index) method and other is by traversing through all the shapes and finding the picture frame. Every picture frame has picture, however, Every picture may not have picture frame i.e picture can be contained inside rectangle, ellipse or in background. But in any form the picture will have the postilion that is retrieved by Shape.getX() and Shape.getY() methods. The height and width can be retrieved on shape level by Shape.getHeight() and Shape.getWidt(). if the pictures are accessed from picture array in Presentation class then in that case, you can only retrieve the height and width of image. Please use the following code snippet to serve your task.

Presentation Pres= new Presentation("D:\\MyShape.ppt");
Slide sld=Pres.getSlides().get(0);
int iH,iW,iX,iY;
Shape shp;
Picture pic=Pres.getPictures ().get(0);
iH=pic.getHeight ();
iW=pic.getWidth ();

for(int i=0;i<sld.getShapes().size ();i++)
{
shp=sld.getShapes().get (i);
if(shp instanceof PictureFrame)
{
iH=shp.getHeight ();
iW=shp.getWidth ();
iX=shp.getX ();
iY=shp.getY();;
}
}

Thanks and Regards,

Hi ,

By the above code I got the height , width , X and Y position but I want to modify image that is on third slide ,how to know which image is that ,as i could retrieve image from presentation object not from the slide . Is there a pattern by which it retrieves images or Identify which image to picked first.

Thanks
Rahul

Dear Rahul,

You can identify the images on slides levels as well. But the issue is that the image may be in any form. It can be a background image in some text frame, it may be an image in the Ole Frame or Table cell background. It can be an image in Picture Frame or Video Frame as well. So, for this you need to be sure that your desired image resides in which of mentioned shapes. One way to achieve this is to use Alternative Text property by setting a user defined name to slide shape that contain the image. Then you may proceed to desired slide and traverse through all the shapes and selects the one matching the name that you set in Alternative text property and then extract that image. Hope it clears your query.

Thanks and Regards,

Hi

Currently I am assuming I only have images in pictureframe.
As of now I am using the below code to retrieve images, but this code picks the image in the order they are put on the slide suppose
on slide 1 I have image1
on slide 2 I have image2
on slide 3 I have image3
so it retrieves the image as {image1, image2 ,image3}
and now if I interchange the image on slide 2 with 3 It still retrieve image as {image1, image2 ,image3}not as{image1, image3 ,image}

so all my calculation of which image belongs to which slide go wrong

Please let me know can I retrieve image at slide level, and how can I know which image belongs to which slide.


pictureFrameList = new ArrayList()
def pic = presentation.getPictures()
for (picSize in 0…pic.size()-1)
{
PictureFrames pictureFrames = new PictureFrames()
byte[] b = null
System.out.println(“picSize “+picSize);
b = pic.get(picSize).getImage()
def imageFormatInt = pic.get(picSize).getImageFormat()
def picId = pic.get(picSize).getPictureId()
def imageFormatStr = “”
switch (imageFormatInt)
{
case 1 : imageFormatStr = “UNKNOWN”
break
case 2 : imageFormatStr = “EMF”
break
case 3 : imageFormatStr = “WMF”
break
case 4 : imageFormatStr = “PICT”
break
case 5 : imageFormatStr = “jpeg”
break
case 6 : imageFormatStr = “png”
break
case 7 : imageFormatStr = “DIB”
break
}
pictureFrames.setImageFormat(imageFormatStr)
def picName = “C:\images\”+picSize
pictureFrames.setPicName(picName)
def fstr = new FileOutputStream(new File(picName+”.”+imageFormatStr));
fstr.write(b, 0, b.size());
fstr.flush();
fstr.close();
pictureFrameList[picSize] = pictureFrames
}

Hi ,

you mentioned that there are two ways to retrieve the image
1. Presentation.getpicture().get(0)
2. Find the pictureframe

I am getting the picture frame but not the actual picture from the second method I want the actual picture that is byte b=getImage()

Please let me know how can I retrieve that .

I can get that from the from presentation but I dont know that which picture belongs to which pictureframe.


Thanks
Rahul

Dear Rahul,

I have written the code snippet for you which will facilitate you to go to any particular slide and retrieve the image inside the PictureFrame. Please fell free to share if you feel any issue while using the code snippet. For your kind reference, the presentation is also attached.

Presentation Pres= new Presentation(path+"Pre.ppt");

Slide sld=Pres.getSlides().get(0);

com.aspose.slides.Shape shp;

for(int s=0;s<Pres.getSlides ().size ();s++)
{
sld=Pres.getSlides().get(s);
for(int i=0;i<sld.getShapes().size ();i++)
{


shp=sld.getShapes().get (i);

if(shp instanceof PictureFrame)
{
System.out.println("The Slide "+ (s+1) +" has Image with Alternative Text: "+shp.getAlternativeText ());

PictureFrame pF=(PictureFrame)shp;

int PicId=pF.getPictureId();

com.aspose.slides.Picture SlidePic=Pres.getPictures ().get(PicId);

}
}
}

Thanks and Regards,