ImageUtil.ImagesFolder.CreateImageList C# (CSharp) Method

CreateImageList() public method

public CreateImageList ( ) : ImageList
return System.Windows.Forms.ImageList
		public ImageList CreateImageList()
		{
			var il = new ImageList();

			if (_images.Count > 0)
			{
				int maxw = 0, maxh = 0;
				foreach (var info in _images.Values)
				{
					if (maxw < info.Image.Width)
						maxw = info.Image.Width;
					if (maxh < info.Image.Height)
						maxh = info.Image.Height;
				}
				if (maxw > 64)
					maxw = 64;
				if (maxh > 64)
					maxh = 64;

				il.ImageSize = new Size(maxw, maxh);

				foreach (var info in _images.Values)
				{
					var scale = Math.Min((float)maxw / info.Image.Width, (float)maxh / info.Image.Height);
					var w = scale < 1.0f ? (int)(scale * info.Image.Width) : info.Image.Width;
					var h = scale < 1.0f ? (int)(scale * info.Image.Height) : info.Image.Height;
					var x = (maxw - w) / 2;
					var y = (maxh - h) / 2;

					Image img = new Bitmap(maxw, maxh);
					using (var g = Graphics.FromImage(img))
						g.DrawImage(info.Image, x, y, w, h);
					il.Images.Add(info.ShortName, img);
				}
			}

			return il;
		}

Usage Example

Ejemplo n.º 1
0
        private void UpdateImagesListImageList(ImagesFolder folder)
        {
            var il = _imagesList.LargeImageList;

            _imagesList.LargeImageList = folder.CreateImageList();
            if (il != null)
            {
                il.Dispose();
            }
        }
All Usage Examples Of ImageUtil.ImagesFolder::CreateImageList