Recent

Author Topic: Select rectangle of the image  (Read 905 times)

backprop

  • Full Member
  • ***
  • Posts: 195
Select rectangle of the image
« on: February 11, 2026, 08:42:10 pm »
I'm trying to create reliable, multi-platform solution to select and copy part of an image from given source. So far I have found some problems and code looks quite weird...

Here is attempt with GTK2 which works as expected using DrawFocusRect(), but that is not how this should be done on Windows and with Delphi... As I explained in the source, for GTK2 need to be done extra care to add DrawFocusRect(), otherwise white dot will remain on the TImage canvas, if not multiple trails of rectangle when moving.

I think on Delphi this was much easier, no need to care about calling DrawFocusRect() so many times nor to reassign image source...

Can anyone try this code on Windows?


« Last Edit: February 11, 2026, 09:12:29 pm by backprop »

LeP

  • Full Member
  • ***
  • Posts: 202
Re: Select rectangle of the image
« Reply #1 on: February 11, 2026, 09:25:46 pm »
I'm trying it but I don't see any issue (Win 11 last update, FPC 3.2.2 / Lazarus 4.4). Can you expalin better what is the problem ?

Phoenix

  • Full Member
  • ***
  • Posts: 146
Re: Select rectangle of the image
« Reply #2 on: February 11, 2026, 09:28:35 pm »
I think it works here on Windows 10. I'm attaching two png images if you need to check the pixels

lainz

  • Hero Member
  • *****
  • Posts: 4741
  • Web, Desktop & Android developer
    • https://lainz.github.io/
Re: Select rectangle of the image
« Reply #3 on: February 12, 2026, 02:11:34 am »
There is TBGRAImageManipulation in BGRAControls to you have a look...

https://wiki.freepascal.org/BGRAControls#TBGRAImageManipulation

backprop

  • Full Member
  • ***
  • Posts: 195
Re: Select rectangle of the image
« Reply #4 on: February 12, 2026, 11:20:42 am »
Thank you for testing and screenshots. Seems fine on Windows too. it can be removed DrawFocusRect in MouseUp and then to screenshot all in order to see dots as well, thus what exactly is copied on Windows and is it specific range for TRect properly done.

And yes, my next step is to do similar with RGBA components, thanks for the hint.

« Last Edit: February 12, 2026, 11:29:08 am by backprop »

backprop

  • Full Member
  • ***
  • Posts: 195
Re: Select rectangle of the image
« Reply #5 on: February 12, 2026, 05:08:27 pm »
There is TBGRAImageManipulation in BGRAControls to you have a look...

https://wiki.freepascal.org/BGRAControls#TBGRAImageManipulation

I have looked in example, but all is extremely slow, selecting as well. And I assume that is because auto-stretching large or small pictures, as I noted here: 

https://forum.lazarus.freepascal.org/index.php/topic,68178.msg526268.html#msg526268

The library is basically very fast, but because of this on large images, all become more complicated... I need similar as in BGRAImageManipulation example, but selecting should be extremely fast... I will create simple selection sample as with TImage, but now with TBGRAVirtualScreen and hope there will be suitable solution...

backprop

  • Full Member
  • ***
  • Posts: 195
Re: Select rectangle of the image
« Reply #6 on: February 13, 2026, 07:42:14 pm »
Version with BGRAVirtualScreen and using transparent rectangle drawing. But it is way too slow, even for quite small part of the original image. I needed to avoid automatic image stretching, thus I sending slice of an image which is only visible in BGRAVirtualScreen size. Original image  can be even size of 4K, but all is still quite slow (all over approx. with size 100x100) with often "hiccups". All need to be smooth...

AFAIK, all need to be drawn in OnRedraw event and even if is using plain method as in previous example with DrawFocusRect() problems are the same.

« Last Edit: February 13, 2026, 07:51:00 pm by backprop »

backprop

  • Full Member
  • ***
  • Posts: 195
Re: Select rectangle of the image
« Reply #7 on: February 13, 2026, 08:16:27 pm »
Oh, fixed. Drawing on canvas  is so slow... ;)
Drawing image directly and all works as intended.

Bitmap.PutImage(0,0,img, dmSet);


valdir.marcos

  • Hero Member
  • *****
  • Posts: 1176
Re: Select rectangle of the image
« Reply #8 on: February 16, 2026, 10:01:09 am »
Oh, fixed. Drawing on canvas  is so slow... ;)
Drawing image directly and all works as intended.

Bitmap.PutImage(0,0,img, dmSet);
Thanks.

 

TinyPortal © 2005-2018