delphi实现保存和读取图片的方法
<p>本文实例讲述了delphi实现保存和读取图片的方法,是非常实用的技巧。分享给大家供大家参考。具体实现方法如下:</p><p>首先引用jpeg</p>
<p><strong>1.显示图片:</strong></p>
<div class="jb51code">
<pre class="brush:delphi;">
ifOpenPictureDialog.Execute then
begin
img1.Picture.LoadFromFile(OpenPictureDialog.FileName);
btnPicture.Text:=OpenPictureDialog.FileName;
end;
</pre>
</div>
<p><strong>2.保存图片:</strong></p>
<div class="jb51code">
<pre class="brush:delphi;">
var
Stream:TMemoryStream;
Stream := TMemoryStream.Create; // 创建内存流
// 将图片保存到内存流中
img1.Picture.Graphic.SaveToStream(Stream);
ParamByName('picture').LoadFromStream(Stream,ftBlob);
ParamByName('IsSavePicture').Value:='1';
Stream.Free;//用完了马上Free掉
</pre>
</div>
<p><strong>3.读取图片:</strong></p>
<div class="jb51code">
<pre class="brush:delphi;">
var
Stream:TMemoryStream;
Jpg:TjpegImage;
if fieldbyname('IsSavePicture').Value='1' then
begin
Stream:=TMemoryStream.Create ;
Jpg:=TjpegImage.Create ;
TBlobField(FieldByName('picture')).SaveToStream(Stream);// 显示的转换为BlobField并保存到内存流
Stream.Position :=0;
jpg.LoadFromStream(Stream);// 加载图片
img1.Picture.Assign(Jpg);
Stream.Free;
Jpg.Free;
end
else
begin
img1.Picture :=nil;
</pre>
</div>
<p>相信本文所述对大家的Delphi程序设计有一定的借鉴价值。</p>
<div class="art_xg">
<b>您可能感兴趣的文章:</b><ul><li>Delphi基本图像处理方法汇总</li><li>Delphi实现窗体感知鼠标滑过并自动隐藏与显示窗口的方法</li><li>delphi实现将BMP格式图形转化为JPG格式图形的方法</li><li>delphi字符串分隔函数用法实例</li><li>Delphi7中群发Email邮件的方法</li><li>Delphi远程连接Mysql的实现方法</li><li>Delphi实现获取进程列表及相关信息的实例</li></ul>
</div>
</div>
<!--endmain-->
頁:
[1]