姬霓太美 發表於 2020-9-1 15:16:00

Delphi Timage 介绍和操作[1](图片判断、清空、类型)

<p><span style="font-size: 16px"><strong>Delphi Timage 操作(图片判断、清空、类型)</strong></span></p>
<p><span style="font-size: 16px"><strong>1、<strong>Timage&nbsp;</strong>介绍</strong></span></p>
<p><span style="font-size: 16px">1.1 介绍</span></p>
<p style="margin-left: 30px"><span style="font-size: 16px">TImage 组件的的使用,主要功能是显示图像、美化界面。TImage 组件经常和TPanel 组件结合使用,以TPanel 组件的边框来划分TImage 组件的边界。在Image 组件调用图片时,可以利用Picture 属性进行指定,也可以在程序中用Picture.LoadFromFile()方法进行调入。利用Picture.SaveToFile()方法可以将TImage 组件的当前显示内容保存为一个图像文件。</span></p>
<p><span style="font-size: 16px">1.2 属性</span></p>
<ul>
<li><span style="font-size: 16px">AutoSize //如果此属性设置为True,TImage 组件将自动调整尺寸,以适应图像的大小</span></li>
<li><span style="font-size: 16px">Canvas //此属性返回图像的画布,是本组件重要的属性,将在后面的章节中详细介绍</span></li>
<li><span style="font-size: 16px">Center //如果此属性设置为True,图像将居中显示</span></li>
<li><span style="font-size: 16px">Picture //用于指定TImage 组件上要显示的图像</span></li>
<li><span style="font-size: 16px">Proportional //如果此属性设置为True,图像的尺寸将按原来长宽的比例自动调整</span></li>
<li><span style="font-size: 16px">Stretch //如果此属性设置为True,图像的尺寸将自动调整并且总是撑满整个TImage 组件</span></li>
<li><span style="font-size: 16px">Transparent //如果此属性设为True,图像为透明的,只适合用于图像是BMP 格式</span></li>
</ul>
<p><span style="font-size: 16px"><strong>2、操作</strong></span></p>
<p><span style="font-size: 16px">判断是否有图片:</span></p>
<div class="cnblogs_Highlighter">
<pre class="brush:delphi;gutter:true;"><span style="font-size: 16px">if Image1.Picture.Graphic=nil then showmessage('无图');
if Image1.Picture.Bitmap.Empty then showmessage('无图');//只对bitmap图有效</span></pre>
</div>
<p><span style="font-size: 16px">清空图片:</span></p>
<div class="cnblogs_Highlighter">
<pre class="brush:delphi;gutter:true;"><span style="font-size: 16px">Image1.Picture.Graphic = nil;   //清空</span></pre>
</div>
<p><span style="font-size: 16px">判断图片类型:</span></p>
<div class="cnblogs_Highlighter">
<pre class="brush:delphi;gutter:true;"><span style="font-size: 16px">Image1.Picture.Graphic is TBitmap//bmp
Image1.Picture.Graphic is TJPEGImage //jpg</span></pre>
</div>
<p><span style="font-size: 16px">加载和保存图片:</span></p>
<div class="cnblogs_Highlighter">
<pre class="brush:delphi;gutter:true;"><span style="font-size: 16px">Image1.Picture.LoadFromFile(const Filename:String);   //打开图片
Image1.Picture.SaveToFile(const Filename:String);   //保存图像
</span></pre>
</div>
<p><span style="font-size: 16px">  </span></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><span style="color: rgba(136, 136, 136, 1)">创建时间:2020.09.01  更新时间:2020.09.02</span></p>
<p>&nbsp;</p>

</div>
<div id="MySignature" role="contentinfo">
    博客园 滔Roy https://www.cnblogs.com/guorongtao 希望内容对你有所帮助,谢谢!<br><br>
来源:https://www.cnblogs.com/guorongtao/p/13596329.html
頁: [1]
查看完整版本: Delphi Timage 介绍和操作[1](图片判断、清空、类型)