■ TileView 클래스의 GetThumbnailImage 이벤트를 사용해 썸네일을 비동기 생성하는 방법을 보여준다.
▶ MainForm.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
using System; using System.Collections.Generic; using System.Drawing; using System.Drawing.Drawing2D; using DevExpress.Utils; using DevExpress.XtraEditors; namespace TestProject { /// <summary> /// 메인 폼 /// </summary> public partial class MainForm : XtraForm { //////////////////////////////////////////////////////////////////////////////////////////////////// Field ////////////////////////////////////////////////////////////////////////////////////////// Private #region Field /// <summary> /// 텍스처 리스트 /// </summary> private List<Texture> textureList; #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainForm() /// <summary> /// 생성자 /// </summary> public MainForm() { InitializeComponent(); #region 텍스처 리스트를 설정한다. this.textureList = new List<Texture>(); Array colorNameArray = Enum.GetNames(typeof(KnownColor)); foreach(object colorName in colorNameArray ) { this.textureList.Add(new Texture(colorName.ToString())); } #endregion this.gridControl.DataSource = textureList; #region 타일 뷰를 설정한다. this.tileView.ColumnSet.BackgroundImageColumn = nameColumn; this.tileView.OptionsTiles.ItemSize = new Size(90, 40); this.tileView.OptionsImageLoad.AsyncLoad = true; this.tileView.OptionsImageLoad.LoadThumbnailImagesFromDataSource = false; this.tileView.OptionsImageLoad.RandomShow = true; #endregion this.tileView.GetThumbnailImage += tileView_GetThumbnailImage; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Private //////////////////////////////////////////////////////////////////////////////// Event #region 타일 뷰 썸네일 이미지 구하기 - tileView_GetThumbnailImage(sender, e) /// <summary> /// 타일 뷰 썸네일 이미지 구하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void tileView_GetThumbnailImage(object sender, ThumbnailImageEventArgs e) { string colorName = this.textureList[e.DataSourceIndex].Name; e.ThumbnailImage = GetBitmap(e.DesiredThumbnailSize, colorName); } #endregion //////////////////////////////////////////////////////////////////////////////// Function #region 비트맵 구하기 - GetBitmap(bitmapSize, colorName) /// <summary> /// 비트맵 구하기 /// </summary> /// <param name="bitmapSize">비트맵 크기</param> /// <param name="colorName">색상명</param> /// <returns>비트맵</returns> private Bitmap GetBitmap(Size bitmapSize, string colorName) { Bitmap bitmap = new Bitmap(bitmapSize.Width, bitmapSize.Height); using(Graphics graphics = Graphics.FromImage(bitmap)) { Color color = Color.FromName(colorName); GraphicsUnit graphicsUnit = GraphicsUnit.Pixel; RectangleF rectangle = bitmap.GetBounds(ref graphicsUnit); using(LinearGradientBrush brush = new LinearGradientBrush(rectangle, Color.White, Color.White, 45, false)) { ColorBlend colorBlend = new ColorBlend(4); colorBlend.Colors = new Color[4] { Color.White, color, color, Color.White }; colorBlend.Positions = new float[4] { 0f, 0.5f, 0.7f, 1f }; brush.InterpolationColors = colorBlend; graphics.FillRectangle(brush, rectangle); } } return bitmap; } #endregion } } |