첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
유용한 소스 코드가 있으면 icodebroker@naver.com으로 보내주시면 감사합니다.
블로그 자료는 자유롭게 사용하세요.

■ TileView 클래스 : GetThumbnailImage 이벤트를 사용해 썸네일 비동기 생성하기

------------------------------------------------------------------------------------------------------------------------


TestProject.zip


MainForm.cs

 

 

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

    }

}

 

------------------------------------------------------------------------------------------------------------------------

Posted by 사용자 icodebroker
TAG

댓글을 달아 주세요