通过单击listview中的项将图像加载到imageviewer时,我得到了重影图像

通过单击listview中的项将图像加载到imageviewer时,我得到了重影图像,listview,delphi,firemonkey,delphi-10-seattle,loadimage,Listview,Delphi,Firemonkey,Delphi 10 Seattle,Loadimage,问题:如何删除后像 详情: 我使用的是delphi xe10。我正在制作简单的imageview应用程序。 计算机规格:I7 6700HQ,Ram16G。Windows10,64位 我在表单上设置了Opendialog、ImageViewer、ListView和按钮。未更改默认名称,因为它用于测试 下面是这个程序的程序。 1.点击按钮设置目录。 2.然后我可以在Listview的目录中看到文件名 3.单击listview中的项目。 4.可以在ImageViewer中查看图像 它运行良好。但后

问题:如何删除后像

详情: 我使用的是delphi xe10。我正在制作简单的imageview应用程序。 计算机规格:I7 6700HQ,Ram16G。Windows10,64位

我在表单上设置了Opendialog、ImageViewer、ListView和按钮。未更改默认名称,因为它用于测试

下面是这个程序的程序。 1.点击按钮设置目录。 2.然后我可以在Listview的目录中看到文件名 3.单击listview中的项目。 4.可以在ImageViewer中查看图像

它运行良好。但后像仍然像一幅马赛克。所以,我试过了

image1.free;
image1.canvas.free;
image1.bitmap.free;
最后,添加下面的代码。但是没有起作用

if Assigned(ImageViewer1.Bitmap) then
begin
ImageViewer1.Bitmap.Clear(0);
end;
有什么需要我再试试的吗

这是我的完整代码

unit app4VIew;

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Classes,
  System.Variants,
  FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs,
  FMX.ListView.Types, FMX.ListView.Appearances, FMX.ListView.Adapters.Base,
  FMX.Controls.Presentation, FMX.StdCtrls, FMX.ListView, FMX.Layouts,
  FMX.ExtCtrls, FMX.Objects;

type
  TForm1 = class(TForm)
    ListView1: TListView;
    SpeedButton1: TSpeedButton;
    OpenDialog1: TOpenDialog;
    ImageViewer1: TImageViewer;
    procedure SpeedButton1Click(Sender: TObject);
    procedure ListView1ItemClick(const Sender: TObject;
      const AItem: TListViewItem);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  chosenDirectory: string;
  SR: TsearchRec;
  Litem: TListViewItem;

implementation

{$R *.fmx}



{ In the form There are Opendialog, ImageViewer, ListView. *}


//when click item in listview, imagefile appear in
procedure TForm1.ListView1ItemClick(const Sender: TObject;
  const AItem: TListViewItem);
var
  Image1: TBitmap;

begin
  //if already imageviewer1.bitmap assigned then free it for initializing imageviewer
  //Question1: I suppose it make easy memory load or some conflict. Just feeling. Am I right?
    if Assigned(ImageViewer1.Bitmap) then
    begin
    ImageViewer1.Bitmap.Clear(0);
    end;

  //Question2: There is afterimage look like mosaic. Why? I freed image before load.
  try
    Image1 := TBitmap.CreateFromFile(chosenDirectory + '\' + ListView1.Items
      [ListView1.Selected.Index].Text);
    Image1.Resize(round(ImageViewer1.Width)-100, round(ImageViewer1.Canvas.Height)-100);
    ImageViewer1.Bitmap.Assign(Image1);
  finally
    Image1.Free;
  end;
end;


//List files in selected directory to Listview
procedure TForm1.SpeedButton1Click(Sender: TObject);
var
  Res: Integer; // count number of files

begin
  if SelectDirectory('Select a directory', 'C:\', chosenDirectory) then
  begin
    //find file in the Directry and assign the result to SR
    Res := FindFirst(chosenDirectory + '\*.*', faAnyFile, SR);
    if Res = 0 then
      repeat
        //and give the result SR to ListView as Itrm as SR.name
        Litem := ListView1.Items.Add();
        Litem.Text := SR.Name;
      until FindNext(SR) <> 0;
    FindClose(SR);
  end;

end;

end.
单元app4VIew;
接口
使用
System.SysUtils、System.TYPE、System.UITYPE、System.Classes、,
系统变量,
FMX.类型,FMX.控件,FMX.窗体,FMX.图形,FMX.对话框,
FMX.ListView.Types、FMX.ListView.Appearances、FMX.ListView.Adapters.Base、,
FMX.Controls.Presentation、FMX.StdCtrls、FMX.ListView、FMX.Layouts、,
FMX.ExtCtrls,FMX.Objects;
类型
TForm1=类(TForm)
ListView1:TListView;
SpeedButton1:TSpeedButton;
OpenDialog1:TopEndDialog;
ImageViewer1:TImageViewer;
程序速度按钮1点击(发件人:ToObject);
过程ListView1ItemClick(常量发送方:ToObject;
常数:TListViewItem);
私有的
{私有声明}
公众的
{公开声明}
结束;
变量
表1:TForm1;
chosenDirectory:string;
SR:TsearchRec;
Litem:TListViewItem;
实施
{$R*.fmx}
{表单中有Opendialog、ImageViewer、ListView.*}
//单击listview中的项目时,imagefile将显示在
过程TForm1.ListView1ItemClick(常量发送方:ToObject;
常数:TListViewItem);
变量
图1:TBitmap;
开始
//如果已分配imageviewer1.位图,则释放它以初始化imageviewer
//问题1:我想这会使内存加载变得很容易,或者产生一些冲突。只是感觉。我说得对吗?
如果指定了(ImageViewer1.Bitmap),则
开始
ImageViewer1.Bitmap.Clear(0);
结束;
//问题2:后像看起来像马赛克。为什么?我在加载前释放了图像。
尝试
Image1:=TBitmap.CreateFromFile(ChoSendDirectory+'\'+ListView1.Items
[ListView1.Selected.Index].Text];
Image1.调整大小(圆形(ImageViewer1.宽度)-100,圆形(ImageViewer1.画布.高度)-100);
ImageViewer1.Bitmap.Assign(Image1);
最后
图1.免费;
结束;
结束;
//将选定目录中的文件列表到Listview
步骤t用于M1.SpeedButton1Click(发件人:ToObject);
变量
Res:Integer;//计算文件数
开始
如果选择目录('Select a directory','C:\',chosenDirectory),则
开始
//在目录中查找文件并将结果分配给SR
Res:=FindFirst(chosenDirectory+'\*.*',faAnyFile,SR);
如果Res=0,则
重复
//并将结果SR作为Itrm作为SR.name提供给ListView
Litem:=ListView1.Items.Add();
文字:=高级名称;
直到FindNext(SR)0;
FindClose(SR);
结束;
结束;
结束。

请你问个问题好吗?我不知道你说的后像是什么意思,我想在
清除后会留下某种gost图像。无论如何,我不能用XE7复制它。也许可以在你的问题中添加一个图片(小但大到足以演示)。我可以在Delphi10西雅图中确认一个问题,但在XE7中不能。它似乎取决于图像大小,但目前无法查找任何“规则”。你可能想向我报告,我无法在西雅图复制(版本23.0.20618.2753,无更新)。Win7,为32/64位编译没有任何区别。默认调试和发布配置都可以正常工作@汤姆布伦伯格-你测试了什么版本的windows?@J。。。我在Win7中测试了32位。后来当我测试时,XE7(在同一台机器上)也出现了这种情况。如果我注释掉了
Image1.Resize()
,问题就消失了。我测试了16x16BMP和png,以及更大的,比如32x32和200X150,bmp和png。问题是随机出现的,这意味着给定的图像并不总是显示错误。另一个观察结果是,如果用鼠标滚轮缩放,问题似乎消失了。这些都是经过非常少的测试(或者我应该说是尝试)的观察结果。