Hi Nitin,
Thanks for your inquiry. Please try using the following code snippet to be able to resize images in a Document:
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, newIntPtr());
return outputImage;
}
Also, please note that Images are represented by either Shape or by DrawingML nodes in Aspose.Words’ DOM. I would suggest you please read the following articles:
https://docs.aspose.com/words/net/working-with-graphic-elements/
https://docs.aspose.com/words/net/working-with-images/
I hope, this will help.
Best Regards,