Extrack Images from Word

Hi,

Iam extracting images from word to a specific folder.i want to extract the images as wmf format and the size should be same as in the word file rather than it’s actual size.

Thanks,

srinivas

Hi
Thanks for your inquiry. You can resize images during extracting from word document. See the following code.

Document doc = new Document(@"359_102751_srinivasgoud\in.doc");
NodeCollection shapes = doc.GetChildNodes(NodeType.Shape, true, false);
int imageIndex = 0;
foreach (Shape shape in shapes)
{
    if (shape.HasImage)
    {
        string imageFileName = string.Format("Out{0}.{1}", imageIndex, shape.ImageData.ImageType);
        MemoryStream stream = new MemoryStream(shape.ImageData.ImageBytes);
        Image img = Image.FromStream(stream);
        img = ResizeImage(img, (int)(shape.Width / 0.75), (int)(shape.Height / 0.75));
        img.Save(@"359_102751_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.

Hi,

Thanks for reply.

if we create the thumbnail image, the charecters in the image are blured.i want the Images to be extracted with same size that are in word document.

i donot want to resize the image.

regards

Srinivas

added to the above…

The Images are of any size, we can copy paste them in word document. we can resize the image afterpasting the image to fit in the word document.

i want to extract the images as it is that are in word document.

i think you got my question

Hi
I understood your task. But I can’t see any other way to solve it. The images in the word document are saved with their original size.
Could you please attach your document here (only you and Aspose staff can download it)? I will try to find solution for you.
Best regards.