# ConvertIconToBitmap
{: .no_toc }

Converts an icon picture into a bitmap picture.

Syntax: **ConvertIconToBitmap(** *IconPicture* [ **,** *BackColor* ] **)** **As Object**

*IconPicture*
: *required* **Object**. An **stdole.StdPicture** holding an icon (`vbPicTypeIcon`) or cursor (`vbPicTypeIcon`).

*BackColor*
: *optional* **Variant**. The background colour to flatten transparent pixels onto, given as an OLE colour value. If omitted, the system **Window** colour is used.

The returned picture is a fresh bitmap-typed **stdole.StdPicture** with the icon rasterised on top of the chosen background. The original icon picture is unchanged.

> [!WARNING] BETA 1045
> An *IconPicture* of **Nothing** ends the program with an access violation, in a 32-bit and a 64-bit build alike.

### Common Errors

| Error | When |
|---|---|
| [-2147467259 (`&H80004005`)](/Reference/Run-time-Errors.md#-2147467259), *Unspecified error* | *IconPicture* is not an icon: a bitmap, a picture with no image, or an object that is not a picture |
| [5 (`&H5`)](/Reference/Run-time-Errors.md#5), *Invalid procedure call or argument* | *BackColor*'s high byte is other than 0, 1, 2 or &H80 (-1, for one), or it is a system colour above &H8000001E |
| [13 (`&HD`)](/Reference/Run-time-Errors.md#13), *Type mismatch* | *BackColor* is a string that does not hold a number |
| [94 (`&H5E`)](/Reference/Run-time-Errors.md#94), *Invalid use of Null* | *BackColor* is **Null** |
| [424 (`&H1A8`)](/Reference/Run-time-Errors.md#424), *Object required* | *IconPicture* is **Null** |

### Example

```tb check_build
Dim MyIconPicture As StdPicture
Dim Bmp As StdPicture
Set Bmp = ConvertIconToBitmap(MyIconPicture, RGB(255, 255, 255))
Set Picture1.Picture = Bmp
```

### See Also

- [CreateStdPictureFromHandle](/tB/Modules/HiddenModule/CreateStdPictureFromHandle.md) function
- [PictureToByteArray](/tB/Modules/HiddenModule/PictureToByteArray.md) function
