none
Images in a ribbon gallery get blurry RRS feed

  • Question

  • Hi,

    I'm developing a Word VSTO Addin and got an issue when using images in a gallery.

    My ribbon XML Code:

    <gallery id="GalleryInsertStyle" getVisible="GetVisible" showImage="true" getLabel="GetLabel" size="large" getScreentip="GetScreenTip" getSupertip="GetSuperTip" getImage="GetImage" columns="1" getItemCount="StyleGalleryGetItemCount" getItemImage="StyleGalleryGetItemImage"  onAction="StyleGalleryAction">

    I've created a solid black image (png) which size is 160 x 25 px.
    When displayed in my gallery its size is 200 x 31 px (I've created a screenshot of the gallery).

    I've now changed the size of my image to 200 x 31 px.
    When displayed in my gallery the size is now 250 x 39 px.

    The same happens when I'm using a jpg or bmp image.

    Here's my code to convert the image to a IPictureDisp:

     using (var image = Image.FromFile(path))
                    {
                        return PictureConverter.ImageToPictureDisp(image);
                    }
    
     public class PictureConverter : AxHost
        {
            private PictureConverter() : base(String.Empty) { }
    
            public static stdole.IPictureDisp ImageToPictureDisp(Image image)
            {
                return GetIPictureDispFromPicture(image) as stdole.IPictureDisp;
            }       
    
        }

    Is there a way to prevent Word from resizing the image?

    Kind regards,

    OrangeTomato


    Thursday, July 5, 2018 2:37 PM

All replies

  • I've just noticed that my Windows display scaling is set to 125%.

    The images get resized to 125% of their initial size. So I guess it's related to the scaling setting of Windows.

    Is there a way to prevent this behavior?

    Kind regards,

    OrangeTomato

    Friday, July 6, 2018 8:51 AM
  • Hello,

    There are two main ways for implementing the required functionality:

    1. You may try to use *.ico files with multiple images embedded. An appropriate images should be picked up.

    2. You need to track DPI values and its changes and return appropriate images depending on the DPI value set. The getImage callback can be used for that. 

    You can customize the Ribbon UI by using callback procedures in COM add-ins. For each of the callbacks the add-in implements, the responses are cached. For example, if an add-in writer implements the getImage callback procedure for a button, the function is called once, the image loads, and then if the image needs to be updated, the cached image is used instead of recalling the procedure. This process remains in-place until the add-in signals that the cached values are invalid by using the Invalidate method, at which time, the callback procedure is again called and the return response is cached. The add-in can then force an immediate update of the UI by calling the Refresh method.

    In the following example, starting the host application triggers the onLoad event procedure that then calls a procedure which creates an object representing the Ribbon UI. Next, a callback procedure is defined that invalidates all of the controls on the UI and then refreshes the UI.

    <customUI … onLoad=”MyAddInInitialize” …>
    
    …
    
    Dim MyRibbon As IRibbonUI
    Sub MyAddInInitialize(Ribbon As IRibbonUI)
        Set MyRibbon = Ribbon
    End Sub
    
    Sub myFunction()
        ‘ Invalidates the caches of all of this add-in’s controls 
        MyRibbon.Invalidate()            
    End Sub<customUI … onLoad=”MyAddInInitialize” …>
    The following is the callback method for the onLoad event:
    VB
    
    Dim MyRibbon As IRibbonUI
    Sub MyAddInInitialize(Ribbon As IRibbonUI)
        Set MyRibbon = Ribbon
    End Sub
    
    Sub myFunction()
        ‘ Invalidates the caches of all of this add-in’s controls 
        MyRibbon.Invalidate()            
    End Sub

    Read more about the Fluent UI (aka Ribbon UI) in the following series of articles:

    1. Customizing the 2007 Office Fluent Ribbon for Developers (Part 1 of 3)

    2. Customizing the 2007 Office Fluent Ribbon for Developers (Part 2 of 3)

    3. Customizing the 2007 Office Fluent Ribbon for Developers (Part 3 of 3)



    profile for Eugene Astafiev at Stack Overflow, Q&A for professional and enthusiast programmers


    Monday, July 9, 2018 9:25 PM
  • Thanks for your reply.

    I guess your solution is related to ribbon icons. I'm talking about showing images in a dynamic gallery (using icons here doesn't help as I have to convert them to a bitmap to get its IPictureDisp).

    Kind regards

    OrangeTomato

    Thursday, July 12, 2018 7:17 AM
  • /bump
    Monday, July 30, 2018 12:29 PM