2

Question: How can I remove afterimage?

ghost images

ghost images

Detail: I'm using delphi xe10. I'm making simple imageview app. Computer specification: I7 6700HQ, Ram16G. Windows10, 64bit.

I set Opendialog, ImageViewer, ListView, Button on the form. Did not change default name cause it's for test.

Below is procedure of this program. 1. click button for setting directory. 2. Then I can see filenames in the directory at Listview 3. click item in listview. 4. Can see image in ImageViewer

It is working well. But afterimage is remained like a mosaic. So, I have tried

image1.free;
image1.canvas.free;
image1.bitmap.free;

finally, add below code. But didn't work.

if Assigned(ImageViewer1.Bitmap) then
begin
ImageViewer1.Bitmap.Clear(0);
end;

Anything I need to try something more?

Here is my complete code.

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.
randomwalk1225
  • 163
  • 1
  • 1
  • 10
  • 2
    Please can you ask a question – David Heffernan Jun 20 '16 at 08:31
  • Oh my bad. I didn't say what I need. Sorry. – randomwalk1225 Jun 20 '16 at 09:02
  • 1
    I'm not sure what you mean by afterimage, well I guess some kind of gost image remains after `Clear`. Anyway, I can not reproduce it with XE7. Maybe add a image (small but big enough to demo) to your question. – Tom Brunberg Jun 20 '16 at 10:31
  • 1
    I can confirm a problem in Delphi 10 Seattle, but not in XE7. It appears to be dependent on image size, but can't look for any 'rules' right now. You may want to report it to [Embarcadero Quality Portal](https://quality.embarcadero.com/secure/Dashboard.jspa) – Tom Brunberg Jun 20 '16 at 10:57
  • Thank you, Tom. Your confirming helpful to me, so much. – randomwalk1225 Jun 20 '16 at 11:07
  • 1
    I can't replicate this in Seattle (version 23.0.20618.2753, no updates.). Win7, compile for 32/64 bit doesn't make a difference. Default debug and release configs both work ok. @TomBrunberg - what version of windows did you test in? – J... Jun 20 '16 at 12:16
  • 2
    @J... I tested in Win7 32 bit. Later when I tested it occured also with XE7 (on the same machine). If I commented out the `Image1.Resize()` the problem went away. I tested with 16x16 bmp and png as well as with larger, say 32x32 and 200X150, bmp and png. The problem occurs randomly, meaning a given image doesn't always show the error. Another observation, if zooming with the mouse wheel, the problem seems to go away. These are observations with a quite minimal testing (or should I say *trying*). – Tom Brunberg Jun 20 '16 at 12:42
  • 1
    I suggest that you submit a bug report – David Heffernan Jun 20 '16 at 13:02
  • I use window 10 64bit. – randomwalk1225 Jun 20 '16 at 13:24
  • 1
    It is possible to submit big reports from that OS – David Heffernan Jun 21 '16 at 06:23
  • I hope be a valuable test for everyone. I will keep testing more. Thank you for comment and distribute your wisdom. – randomwalk1225 Jun 21 '16 at 08:20

0 Answers0