public static OwnerDrawnItemImageState RetrieveOrCacheImage(ImageList imagelist, string image) { //Check to need to see if the imagelist has been encountered before... if (!keyImageStates.ContainsKey(imagelist)) { if (!watchedImageLists.Contains(imagelist)) { imagelist.Disposed += new EventHandler(imagelist_Disposed); watchedImageLists.Add(imagelist); } keyImageStates.Add(imagelist, new Dictionary <string, OwnerDrawnItemImageState>()); } //Check if the image has been encountered before... if (!keyImageStates[imagelist].ContainsKey(image)) { //When the key exists on the imagelist, obtain a copy of the image //in a System.Drawing.Bitmap object and process the disabled/shadow states. if (imagelist.Images.ContainsKey(image)) { Bitmap normalImage = new Bitmap(imagelist.Images[image]), disabledImage = null, shadowImage = null; ProcessStyles(normalImage, ref disabledImage, ref shadowImage); OwnerDrawnItemImageState imageState = new OwnerDrawnItemImageState(normalImage, disabledImage, shadowImage); keyImageStates[imagelist].Add(image, imageState); return(imageState); } else //No matching key exists... { return(new OwnerDrawnItemImageState()); } } else { //return the cached image. return(keyImageStates[imagelist][image]); } }
public static OwnerDrawnItemImageState RetrieveOrCacheImage(Bitmap image, Color transparencyColor) { if (!(bitmapImageStates.ContainsKey(image))) { //When the image Item isn't inside the state dictionary, copy the base, //and process sub-styles, then insert it into the cache. Bitmap normalImage = new Bitmap((Image)image), disabledImage = null, shadowImage = null; normalImage.MakeTransparent(transparencyColor); //Used to process shadow/disabled states. ProcessStyles(normalImage, ref disabledImage, ref shadowImage); OwnerDrawnItemImageState imageState = new OwnerDrawnItemImageState(normalImage, disabledImage, shadowImage); bitmapImageStates.Add(image, imageState); return(imageState); } else {//Return the cached image. return(bitmapImageStates[image]); } }