Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8534067
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T10:06:35+00:00 2026-06-11T10:06:35+00:00

So I’m using Word.Interloop and in order to compare two pics, I guess I

  • 0

So I’m using Word.Interloop and in order to compare two pics, I guess I have to transform the current picture(in word file) to a bitmap image and then compare it with a bitmap image object from desktop?
Or perhaps the is a simpler way to do so?

Word.InlineShape x;
x.isEqual( Picture from Desktop/ bitmapImage.Object);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T10:06:36+00:00Added an answer on June 11, 2026 at 10:06 am

    I have made a small sample showing how this can be accomplished. The main idea is to represent your image from your desktop as a Bitmap instance and then compare it pixel by pixel to the Bitmap instance in your document. The comparison is done by first copying an inline shape to the clipboard, then turning it into a Bitmap, and then compare it with the reference (from the desktop) – first by size and then pixel by pixel.

    The sample is implemented as a C# console application using .NET 4.5, Microsoft Office Object Library version 15.0, and Microsoft Word Object Library version 15.0.

    using System;
    using System.Drawing;
    using System.Threading;
    using System.Windows.Forms;
    using Application = Microsoft.Office.Interop.Word.Application;
    
    namespace WordDocStats
    {
        class Program
        {
            // General idea is based on: https://stackoverflow.com/a/7937590/700926
            static void Main()
            {
                // Open a doc file
                var wordApplication = new Application();
                var document = wordApplication.Documents.Open(@"C:\Users\Username\Documents\document.docx");
    
                // Load the image to compare against.
                var bitmapToCompareAgainst = new Bitmap(@"C:\Users\Username\Documents\image.png");
    
                // For each inline shape, do a comparison
                // By inspection you can see that the first inline shape have index 1 ( and not zero as one might expect )
                for (var i = 1; i <= wordApplication.ActiveDocument.InlineShapes.Count; i++)
                {
                    // closure
                    // http://confluence.jetbrains.net/display/ReSharper/Access+to+modified+closure
                    var inlineShapeId = i; 
    
                    // parameterized thread start
                    // https://stackoverflow.com/a/1195915/700926
                    var thread = new Thread(() => CompareInlineShapeAndBitmap(inlineShapeId, bitmapToCompareAgainst, wordApplication));
    
                    // STA is needed in order to access the clipboard
                    // https://stackoverflow.com/a/518724/700926
                    thread.SetApartmentState(ApartmentState.STA);
                    thread.Start();
                    thread.Join();
                }
    
                // Close word
                wordApplication.Quit();
                Console.ReadLine();
            }
    
            // General idea is based on: https://stackoverflow.com/a/7937590/700926
            protected static void CompareInlineShapeAndBitmap(int inlineShapeId, Bitmap bitmapToCompareAgainst, Application wordApplication)
            {
                // Get the shape, select, and copy it to the clipboard
                var inlineShape = wordApplication.ActiveDocument.InlineShapes[inlineShapeId];
                inlineShape.Select();
                wordApplication.Selection.Copy();
    
                // Check data is in the clipboard
                if (Clipboard.GetDataObject() != null)
                {
                    var data = Clipboard.GetDataObject();
    
                    // Check if the data conforms to a bitmap format
                    if (data != null && data.GetDataPresent(DataFormats.Bitmap))
                    {
                        // Fetch the image and convert it to a Bitmap
                        var image = (Image)data.GetData(DataFormats.Bitmap, true);
                        var currentBitmap = new Bitmap(image);
                        var imagesAreEqual = true;
    
                        // Compare the images - first by size and then pixel by pixel
                        // Based on: http://www.c-sharpcorner.com/uploadfile/prathore/image-comparison-using-C-Sharp/
                        if(currentBitmap.Width == bitmapToCompareAgainst.Width && currentBitmap.Height == bitmapToCompareAgainst.Height)
                        {
                            for (var i = 0; i < currentBitmap.Width; i++)
                            {
                                if(!imagesAreEqual)
                                    break;
    
                                for (var j = 0; j < currentBitmap.Height; j++)
                                {
                                    if (currentBitmap.GetPixel(i, j).Equals(bitmapToCompareAgainst.GetPixel(i, j)))
                                        continue;
    
                                    imagesAreEqual = false;
                                    break;
                                }
                            }
                        }
                        else
                        {
                            imagesAreEqual = false;
                        }
                        Console.WriteLine("Inline shape #{0} is equal to the 'external' bitmap: {1}", inlineShapeId, imagesAreEqual);
                    }
                    else
                    {
                        Console.WriteLine("Clipboard data is not in an image format");
                    }
                }
                else
                {
                    Console.WriteLine("Clipboard is empty");
                }
            }
        }
    }
    

    References:

    • Threadstart with params: https://stackoverflow.com/a/1195915/700926
    • Extracting inline shapes as images from word in C#: https://stackoverflow.com/a/7937590/700926
    • Comparing images in C#:
      http://www.c-sharpcorner.com/uploadfile/prathore/image-comparison-using-C-Sharp/
    • Details on how to retrieve an image from the clipboard in C#: https://stackoverflow.com/a/998825/700926
    • Details on how to access the clipboard from C#: https://stackoverflow.com/a/518724/700926
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have an autohotkey script which looks up a word in a bilingual dictionary
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I have thousands of HTML files to process using Groovy/Java and I need to
I have a reasonable size flat file database of text documents mostly saved in
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.