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

Free Support Forum - aspose.com

Unit of Shape.Width and Shape.Height

Hello,

what type of Unit has Shape.Width. I've a ppt file includes a couple of Shapes. One of this shape has 4000 width. Is this pixel, point, or whatever?

Thanks in advance...

The short answer exists in our FAQ:


Please check last question.

I have a similar question concerning the units of picture shapes.

I have a template slide which I use with CloneSlide. A shape existing in the template will be replaced by a picture by a PictureFrame. Because I create the picture dynamically, I use the dimensions of the template shape and try to create the picture with these dimensions.

In my example the shape has width of 5980 and height of 3367. When I create the bitmap with these dimensions and add this to the slide, the picture is scaled down to 17%. With 100% it’s much too big. Currently I use an factor of 6 to convert the dimensions of the image to the dimension of the shape, but this factor is not completely correct. Is there any calculation to get the correct factor or some possibility to avoid the factor?

Some source codes:

-> getting the dimensions of the shape:
X = shape.X;
Y = shape.Y;
MaxWidth = shape.Width;
MaxHeight = shape.Height;

-> creating the bitmap
_bitmap = new System.Drawing.Bitmap(MaxWidth, MaxHeight);

-> addiung the bitmap to the slide
AS.Picture pic = new Aspose.Slides.Picture(_destination, _bitmap);
int picId = _destination.Pictures.Add(pic);
AS.PictureFrame pframe = _slide.Shapes.AddPictureFrame(picId, X, Y, MaxWidth, MaxHeight);


Got the problem. When creating a Bitmap without providing a resolution, the framework uses 96 DpI by default. So my factor should be right, because 576 / 96 = 6
The correct syntax to create the bitmap should be
_bitmap = new System.Drawing.Bitmap(MaxWidth, MaxHeight);
_bitmap.SetResolution(576, 576);

Hello,

It’s necessary to use scale factor for images created on the fly or may be in case you need to reduce image size. It 's better to use factors 8, 6 or 4. 8 for low resolution and 4 for high quality presentations. At the same time you don’t need to set resolution of images loaded from file. Just set correct PictureFrame size and MS PowerPoint will do all image resizing for you automatically. For the first case your code will look like this:

-> getting the dimensions of the shape:
float scale = 6f;
X = shape.X;
Y = shape.Y;
MaxWidth = shape.Width;
MaxHeight = shape.Height;

-> creating the bitmap
_bitmap = new System.Drawing.Bitmap((int)(MaxWidth / scale), (int)(MaxHeight / scale));