Recent

Author Topic: Scrolling a BGRABitmap image  (Read 1137 times)

atlatl

  • New Member
  • *
  • Posts: 21
Scrolling a BGRABitmap image
« on: January 27, 2025, 10:19:37 pm »
I can't get an image to scroll. I calculate the location the image should move to in a scrollbarChange handler, then call image.draw(Canvas, x, y, true), and the image dosen't move.

Debugging the scrollbar handler shows the math is correct.

I must be missing some vital step.

Does anyone have an idea of what I'm missing?

Tony Stone

  • Sr. Member
  • ****
  • Posts: 280
Re: Scrolling a BGRABitmap image
« Reply #1 on: January 27, 2025, 10:57:21 pm »
Depending on what you are doing I am pretty sure I used a scrollbox in the past and put a full size image in it.  Made it pretty automatic but this is probably not the best way.

lainz

  • Hero Member
  • *****
  • Posts: 4743
  • Web, Desktop & Android developer
    • https://lainz.github.io/
Re: Scrolling a BGRABitmap image
« Reply #2 on: January 28, 2025, 03:51:05 am »
Share your minimal code. Else who can help you?

Dzandaa

  • Hero Member
  • *****
  • Posts: 544
  • From C# to Lazarus
Re: Scrolling a BGRABitmap image
« Reply #3 on: January 28, 2025, 12:37:21 pm »
Hi,

@atlatl:

Here the minimal project I use as template to open, save and transform, Zoom and Scroll BGRABitmap:

You can use it as if or put in your template directory:

B->
Regards,
Dzandaa

atlatl

  • New Member
  • *
  • Posts: 21
Re: Scrolling a BGRABitmap image
« Reply #4 on: January 28, 2025, 07:31:35 pm »
Thanks for the replys.

@Tony Stone:

"this is probably not the best way" - I'll take your word for it. 😊

@lainz:
Code: Pascal  [Select][+][-]
  1. PROCEDURE TForm1.HScrollBarChange(Sender: TObject);
  2.   BEGIN
  3.     gImageLeft:= HScrollBar.Position * (-gImageSize Div gPortSize);
  4.     IF gImageLeft < -(gImageSize - gPortSize) THEN gImageLeft:= -(gImageSize - gPortSize);
  5.     gImage.draw(Canvas, gImageLeft, gImageRight, true)
  6.   END;
  7.  

It turns out it wasn't the BGRABitmap image that needed to be updated, but the form. Swapping out the gImage.draw call for a Repaint call solved the issue.

@Dzandaa:

Thank you for the "minimal project", that's a lot of code to digest.

It was your use of Repaint in your RedrawPicture handler that clued me in to what I was doing wrong. Thanks.

 

TinyPortal © 2005-2018