0

I cam creating an app for Android with Delphi XE 10.3, Firemonkey. I have tried every possible idea and searched online for days but can't find a solution. I have many PNG images loaded as assets (RT_RCDATA).

var InStream: TResourceStream;
begin
InStream := TResourceStream.Create(HInstance,'PngImage_'+inttostr(trunc(TrackBar2.Value)), RT_RCDATA);
try
Image1.Bitmap.LoadFromStream(InStream);
finally
InStream.Free;
end;
end;

Then every time I click on the button, the image is shown correctly.

But what does not work, (and what I should be able to do) is:

procedure TForm1.Timer1Timer(Sender: TObject);
var InStream: TResourceStream;
begin
InStream := TResourceStream.Create(HInstance, 'PngImage_'+inttostr(imgcount), RT_RCDATA);
label5.Text:='PngImage_'+inttostr(layerCount);
try
Image1.Bitmap.LoadFromStream(InStream);
finally
InStream.Free;
end;
imgcount:=imgcount+1;
//FOrce refresh
//image1.Repaint; // this seems to do nothing
//image1.Visible:=false; image1.Visible:=true;  // this also does nothing to help
//application.processmessages; // neither this one
end

If I try to load and show a sequence of images,with some delay between them, (like an automatic slideshow), then the image is not updated; if I try to show images1-2-3-4, onyly image 4 is shown. I have tried everything, from repaint, refresh methods, hide/show visibility, calling application.processmessages, loading a bitmap and drawing it to form canvas, using a timer, but I can't find a solution.

Thanks

Madaeon
  • 1
  • 1
  • I'm afraid your q is not very clear. a) When you say " only the last image is shown.", if your images are numbered 1-4, do you mean that only image 4 is shown, or what? b) Does your code `inttostr(trunc(TrackBar2.Value))` result in different, correctly numbered images being displayed? – MartynA Dec 08 '18 at 17:32
  • 2
    From your question I understand that the code you show is the code in the button click handler, right? And it works. Then you have some other code that loads several images after each other that doesn't work. So maybe you should start with showing the cpmplete procedure that doesn't work. – Tom Brunberg Dec 08 '18 at 17:33
  • HI, I updated the question with the details. – Madaeon Dec 10 '18 at 11:04
  • This is the event assigned to a TTimer.OnTimer handler, right? Maybe add the code that sets up this timer. – nil Dec 10 '18 at 12:57
  • The code that sets up the timer is timer1.Interval:=1000; timer1.Enabled:=true; – Madaeon Dec 10 '18 at 13:16
  • With a small test project for me changing the Image's Bitmap on a timer did work, `LoadFromStream` seemed to automatically invalidate the Image. I used a `TFileStream` however. – nil Dec 10 '18 at 14:11
  • 1
    I can not reproduce the problem in Delphi XE7 on Windows 7. You have a glitch in your code as you use both `imgcount` and `layercount` to relate to current image, but only update `imgcount`. That, however, only affects what `Label5` displays. Perhaps your actual code is different or perhaps there's something fishy with Delphi 10.3? – Tom Brunberg Dec 10 '18 at 15:57
  • The code in the timer now works. I was trying to get two image changes for each Ontimer call, and the image was never shown; changing the code to one image update for each onTimer call, now it works. Thanks – Madaeon Dec 11 '18 at 15:09

0 Answers0