Hi
Thank you for your interest in Aspose products. You can try to use the following code to achieve this.
public void TestResizeImages_100222()
{
Document doc = new Document(@"307_100222_srinivasgoud\in.doc");
// get shapes collection
NodeCollection shapes = doc.GetChildNodes(NodeType.Shape, true, false);
int imageIndex = 0;
foreach (Shape shape in shapes)
{
if (shape.HasImage)
{
// generate image name
string imageFileName = string.Format("image_{0}.{1}", imageIndex, shape.ImageData.ImageType);
// get image
MemoryStream stream = new MemoryStream(shape.ImageData.ImageBytes);
Image img = Image.FromStream(stream);
// resize image
img = ResizeImage(img, 100, 100);
// save image
img.Save(@"307_100222_srinivasgoud\" + imageFileName);
imageIndex++;
}
}
}
///
/// Resize source image to specifed sze
///
/// Source image
/// Target width
/// Target height
/// Resized image
private Image ResizeImage(Image sourceImage, int targetWidth, int targetHeight)
{
float ratioWidth = (float)sourceImage.Width / targetWidth;
float ratioHeight = (float)sourceImage.Height / targetHeight;
if (ratioWidth > ratioHeight)
targetHeight = (int)(targetHeight * (ratioHeight / ratioWidth));
else
{
if (ratioWidth < ratioHeight)
targetWidth = (int)(targetWidth * (ratioWidth / ratioHeight));
}
Image outputImage = sourceImage.GetThumbnailImage(targetWidth, targetHeight, null, new IntPtr());
return outputImage;
}
I hope that this will help you.
Best regards.