<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>
<channel>
	<title>Serge&#039;s Technology View &#187; canvas</title>
	<atom:link href="http://blog.dragonsoft.us/tag/canvas/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.dragonsoft.us</link>
	<description>Talk about Technologies, Software Architecture and Management</description>
	<lastBuildDate>Tue, 31 Jan 2012 01:43:34 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>TIPS: Draw Image From TImageList</title>
		<link>http://blog.dragonsoft.us/2008/08/28/tips-draw-image-from-timagelist/</link>
		<comments>http://blog.dragonsoft.us/2008/08/28/tips-draw-image-from-timagelist/#comments</comments>
		<pubDate>Thu, 28 Aug 2008 18:56:43 +0000</pubDate>
		<dc:creator>Serguei Dosyukov</dc:creator>
				<category><![CDATA[Delphi]]></category>
		<category><![CDATA[canvas]]></category>
		<category><![CDATA[load imagelist from resource file]]></category>
		<category><![CDATA[timage]]></category>
		<category><![CDATA[timagelist]]></category>
		<guid isPermaLink="false">http://blog.dragonsoft.us/?p=339</guid>
		<description><![CDATA[This question is coming back and again. I have a TImage in many form which shows the status of the item. It requires status image being changed when it is changed. I do not want to use several instances of &#8230; <a href="http://blog.dragonsoft.us/2008/08/28/tips-draw-image-from-timagelist/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>This question is coming back and again.</p>
<blockquote><p>I have a TImage in many form which shows the status of the item. It requires status image being changed when it is changed. I do not want to use several instances of the TImage on the form. Instead I would like to use TImageList to store and share them.</p></blockquote>
<p>Yes, you can. But there are some quirks you have to consider when doing so.</p>
<p>Let&#8217;s say you have state images and you have to draw a different one based on the state.</p>
<p>Let&#8217;s say you have placed Image list and an Image on your form and populated the list with few state images</p>
<pre class="brush: delphi; title: ; notranslate">var
  MyImageList: TImageList;
  MyImage: TImage;</pre>
<h3>Canvas</h3>
<p>That is probably the easiest case. Lets draw an image on canvas of some control (OwnerDraw situation) and also center it. X, Y are top left corner of the future image and Width is a width of the rectangle we want to center image in.<br />
MyImageIndex is an index of the image in the Image List.</p>
<pre class="brush: delphi; title: ; notranslate">MyImageList.Draw(Canvas, X + Width div 2 - MyImageList.Width div 2, Y, MyImageIndex, dsNormal, itImage);</pre>
<h3>TImage</h3>
<p>Being a little bit more complex, it does require some extra code.</p>
<pre class="brush: delphi; title: ; notranslate">// Make sure that any prior state is cleared.
// If you do not do that with transparency enabled, you would see
// images on top of each other
MyImage.Picture.Bitmap := nil;
// Make sure that transparency pixel in the image is taken
// in consideration
MyImage.Picture.Bitmap.TransparentMode := tmFixed;
MyImage.Picture.Bitmap.TransparentColor := clWhite;
// Load image from the Image list into TImage
MyImageList.GetBitmap(MyImageIndex, MyImage.Picture.Bitmap);</pre>
<h3>Can I use resource file?</h3>
<p>Would you like to keep images in the file?</p>
<pre class="brush: delphi; title: ; notranslate">// Store it once
WriteComponentResFile('MyImageList.dat', MyImageList);
// Use it later
ReadComponentResFile('MyImageList.dat', MyImageList);</pre>
<p>Not that difficult after all.</p>
<hr/><span style="font-size: 7pt">Copyright &copy; 2012 <strong><a href="http://blog.dragonsoft.us">Serge&#039;s Technology View</a></strong>. This Feed is for personal non-commercial use only.</span>]]></content:encoded>
			<wfw:commentRss>http://blog.dragonsoft.us/2008/08/28/tips-draw-image-from-timagelist/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

