I have a c# add-in which has a custom ribbon, however, I have no images for the buttons. I do not have a .bmp file, only an .ico. And if it is at all possible, it is preferred not to have to convert anything.
the ribbon is created through xml, not the visual studio ribbon designer
There are two possible ways for getting the job done. Both of them are described in the Customizing the 2007 Office Fluent Ribbon for Developers article in MSDN:
The element's loadImage attribute enables you to specify a callback that can load all images. After you set up this callback procedure, Office calls the callback procedure and passes the string from the image attribute for each control that loads images. You do not need to implement the getImage callback multiple times, such as one time for each control that requires images.
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui"
loadImage="GetImage">
<!-- Later in the markup -->
<button id="myButton" image="image.jpg" />
To supply the button's image, Office calls the GetImage function. It passes the parameter "mypic.jpg" and expects an IPictureDisp object in return. By using this technique, you can write a single callback procedure that returns all the images your customization needs, without having to write each individual control's getImage callback. Note that the loadImage callback is not called again when you call the Ribbon's Invalidate method or InvalidateControl method. For the controls that need to change images dynamically at run time, use the getImage callback.
For example, the callback might look like the following one:
public stdole.IPictureDisp GetImage(string imageName)
{
return
PictureConverter.IconToPictureDisp(Properties.Resources.MyIcon);
}
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui"
loadImage="GetImage">
<!-- Later in the markup -->
<button id="myButton" getImage="GetImageCallback.jpg" />
The getImage callback method must return a stdole.IPictureDisp type, so you usually need to convert your images to this type. To perform these conversions, you can use the following PictureConverter class, which inherits from the AxHost class.
internal class PictureConverter : AxHost
{
private PictureConverter() : base(String.Empty) { }
static public stdole.IPictureDisp ImageToPictureDisp(Image image)
{
return (stdole.IPictureDisp)GetIPictureDispFromPicture(image);
}
static public stdole.IPictureDisp IconToPictureDisp(Icon icon)
{
return ImageToPictureDisp(icon.ToBitmap());
}
static public Image PictureDispToImage(stdole.IPictureDisp picture)
{
return GetPictureFromIPicture(picture);
}
}
For example, the callback might look like the following one:
public stdole.IPictureDisp GetImageCallback(IRibbonControl control)
{
return
PictureConverter.IconToPictureDisp(Properties.Resources.MyIcon);
}
It is up to you wich way is to choose.