Recent

Author Topic: Copyrect not working in Linux  (Read 2244 times)

rebzdu

  • New Member
  • *
  • Posts: 11
Re: Copyrect not working in Linux
« Reply #15 on: December 03, 2020, 03:06:58 pm »
I use TImage.Canvas to draw in the background. If the drawing is complete, I put it in the foreground with CopyRect.
Everything worked find till last year. Now I recompiled the source and have the problems.
If I draw directly in the Canvas of Form1, the screen is flickering, bacause there is a lot to draw.
« Last Edit: December 03, 2020, 03:10:11 pm by rebzdu »

circular

  • Hero Member
  • *****
  • Posts: 4181
    • Personal webpage
Re: Copyrect not working in Linux
« Reply #16 on: December 03, 2020, 03:28:33 pm »
I think you're confused. You don't put a component in foreground with CopyRect. If you want the component to be visible, you would use its Visible property or call the BringToFront function.

Doing CopyRight from the canvas of a component that is not visible is not supposed to work. You were just lucky it worked until now, but that's really not guaranteed to work, depending on the version of the OS or the widgetset.

If you don't want it to flicker, to draw it in one go, you can do that with a TBitmap. That's an image that is not a component, not supposed to be visible, but that you can draw on a surface.

You can achieve this by creating a TBitmap, set its Width and Height, and use its Canvas property. Then put it on the form using the Draw function of the form canvas.
Conscience is the debugger of the mind

rebzdu

  • New Member
  • *
  • Posts: 11
Re: Copyrect not working in Linux
« Reply #17 on: December 05, 2020, 01:17:47 am »
I think you're confused. You don't put a component in foreground with CopyRect.
Perhaps this is my bad english that leads to misunderstandings.

I didn't think, that I put my TempImage in the foreground,
I am aware, that CopyRect makes a copy from its own Canvas to the Canvas of Form1.
I am painting in the background on TempImage (not visible) while the previous image (canvas) of Form1 is visible.

I don't thing that I need TBitmap, TImage is sufficient, which I saw, when I checked my drawing with a call of
Code: [Select]
TempBild.Picture.SaveToFile('TempBild.jpg'); The image, I find afterwards on my harddisk is the one I expected.

Doing CopyRight from the canvas of a component that is not visible is not supposed to work.
I have never seen any supporting document, which mention, that it is necessary, that the image must be visible whilst you call CopyRect

Meanwhile I solved the problem of the flickering in my Windows-Version.
When I created my program (in 1993, with Turbo Pascal/Delphi) my memory was running out, so I set
Code: [Select]
Form1.DoubleBuffered := false to save some memory space.
Meanwhile I have enough memory, that this is no longer necessary, but I didn't kick out this instruction, because there were no problems till now.
Now I had to put CopyRect within FormPaint (see my posts above), so I generated a flickering image in Windows (not in Linux).

Strangely enough, till these changes my program doesn't react to any keystroke after the first one is processed in the Windows-version, but this is another problem.

I'd like to know, why CopyRect must be done within FormPaint, but it is not vital, so my oroiginal problem is solved.

Thanks to everyone

rebzdu
« Last Edit: December 05, 2020, 02:41:01 am by rebzdu »

circular

  • Hero Member
  • *****
  • Posts: 4181
    • Personal webpage
Re: Copyrect not working in Linux
« Reply #18 on: December 05, 2020, 09:55:45 am »
I have the impression I scared you off.  :'(

You are free to do as you wish. I am just trying to explain so that you have a reliable way of doing things.

Quote
Now I had to put CopyRect within FormPaint (see my posts above), so I generated a flickering image in Windows (not in Linux).
The OnPaint event happens just after the background of the form is cleared. So that's the best place to minimize flickering.

If you want to avoid flickering, you can as well disable the LM_ERASEBKGND message and draw in the OnPaint event. So whenever the forms get invalidated, you would redraw its content and there would be no flickering at all.

As I said before, on certain widgetsets, like Qt5 or MacOS, you cannot draw outside of OnPaint at all. That would just display nothing. So it is a good habit to always draw on the controls in OnPaint.

I don't thing that I need TBitmap, TImage is sufficient
In my view, it is the other way around. TImage is TBitmap + a control to display on the screen. So TBitmap is sufficient and TImage is superfluous.

Quote
Doing CopyRight from the canvas of a component that is not visible is not supposed to work.
I have never seen any supporting document, which mention, that it is necessary, that the image must be visible whilst you call CopyRect
The Canvas of the control is the screen unless the system or framework creates a bitmap to store its content (like DoubleBuffered). So doing the CopyRect could just try to copy the pixels from the screen.

TImage.Canvas: the screen or some double-buffer
TImage.Picture.Bitmap.Canvas: the canvas of the image that is supposed to be stored in TImage

That means that there are 3 surfaces here: the screen, the double-buffer, and the image (Picture) that can be stored in TImage.

You could in fact just make the TImage visible and draw in its Picture.Bitmap. This would be a way to use TImage that would make more sense. And enable DoubleBuffer on the form to avoid any flickering when the TImage gets repainted.
Conscience is the debugger of the mind

 

TinyPortal © 2005-2018