Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 4 of 4 total
Thread TCanvas.fillStyle := dsPattern.. (v1 only)
Sat, May 30 2015 12:34 AMPermanent Link

Bruno Larochelle

g'day

this is NOT a question for Sir Tim (who is busy!), but if there is a Uri/Matthew/Raul/Chris/other expert who has run in to this.. i'd love your advice.. Smile

this is a v1 question, and I know that things have changed in v2 with TCanvas (so it does not apply to v2 at all)


I'm trying to draw using on the canvas using a pattern (image) :

pntMain.canvas.fillStyle := dsPattern;
pntMain.canvas.fillPattern.imageName := 'clouds.png';
pntMain.canvas.fillPattern.repeatStyle := rsBoth;
pntMain.canvas.fillRect(0,0,300,300);

this gives an error at run-time saying 'clouds.png' not loaded

If however, in the same mini project, I use a simple TImage, with similar specification, that works fine and it loads the image:

image1.imageName := 'clouds.png';


so.. somehow, the 'imageName' is being treated differently for the TCanvas.fillPattern.imageName vs. the TImage.imageName.


regards.. Bruno
Sat, May 30 2015 6:14 PMPermanent Link

Chris Holland

SEC Solutions Ltd.

Avatar

Team Elevate Team Elevate

You are not giving the image time to load.

Either try this:

procedure TForm1.Form1Create(Sender: TObject);
begin
   pntMain.canvas.fillStyle := dsPattern;
   pntMain.canvas.fillPattern.imageName := 'house.png';
   pntMain.canvas.fillPattern.repeatStyle := rsBoth;

   CanvasTimer.Enabled := true;
end;

procedure TForm1.CanvasTimerTimer(Sender: TObject);
begin
   CanvasTimer.Enabled := false;
   pntMain.canvas.fillRect(0,0,300,300);
end;

I set the Timer delay to 10ms and it worked.
The other option would be to use a TCanvasImage and keep calling the
timer until the 'Loaded' flag for the TCanvasImage is set to true.

Hope this helps.

Chris Holland
[Team Elevate]

On 30/05/2015 05:34, Bruno Larochelle wrote:
> g'day
>
> this is NOT a question for Sir Tim (who is busy!), but if there is a Uri/Matthew/Raul/Chris/other expert who has run in to this.. i'd love your advice.. Smile
>
> this is a v1 question, and I know that things have changed in v2 with TCanvas (so it does not apply to v2 at all)
>
>
> I'm trying to draw using on the canvas using a pattern (image) :
>
> pntMain.canvas.fillStyle := dsPattern;
> pntMain.canvas.fillPattern.imageName := 'clouds.png';
> pntMain.canvas.fillPattern.repeatStyle := rsBoth;
> pntMain.canvas.fillRect(0,0,300,300);
>
> this gives an error at run-time saying 'clouds.png' not loaded
>
> If however, in the same mini project, I use a simple TImage, with similar specification, that works fine and it loads the image:
>
> image1.imageName := 'clouds.png';
>
>
> so.. somehow, the 'imageName' is being treated differently for the TCanvas.fillPattern.imageName vs. the TImage.imageName.
>
>
> regards.. Bruno
>
Sat, May 30 2015 11:54 PMPermanent Link

Bruno Larochelle

thanks Chris, I keep learning the tricks from the masters! that worked exactly as described

.. Bruno


Chris Holland wrote:

You are not giving the image time to load.

Either try this:

procedure TForm1.Form1Create(Sender: TObject);
begin
   pntMain.canvas.fillStyle := dsPattern;
   pntMain.canvas.fillPattern.imageName := 'house.png';
   pntMain.canvas.fillPattern.repeatStyle := rsBoth;

   CanvasTimer.Enabled := true;
end;

procedure TForm1.CanvasTimerTimer(Sender: TObject);
begin
   CanvasTimer.Enabled := false;
   pntMain.canvas.fillRect(0,0,300,300);
end;

I set the Timer delay to 10ms and it worked.
The other option would be to use a TCanvasImage and keep calling the
timer until the 'Loaded' flag for the TCanvasImage is set to true.

Hope this helps.

Chris Holland
[Team Elevate]

On 30/05/2015 05:34, Bruno Larochelle wrote:
> g'day
>
> this is NOT a question for Sir Tim (who is busy!), but if there is a Uri/Matthew/Raul/Chris/other expert who has run in to this.. i'd love your advice.. Smile
>
> this is a v1 question, and I know that things have changed in v2 with TCanvas (so it does not apply to v2 at all)
>
>
> I'm trying to draw using on the canvas using a pattern (image) :
>
> pntMain.canvas.fillStyle := dsPattern;
> pntMain.canvas.fillPattern.imageName := 'clouds.png';
> pntMain.canvas.fillPattern.repeatStyle := rsBoth;
> pntMain.canvas.fillRect(0,0,300,300);
>
> this gives an error at run-time saying 'clouds.png' not loaded
>
> If however, in the same mini project, I use a simple TImage, with similar specification, that works fine and it loads the image:
>
> image1.imageName := 'clouds.png';
>
>
> so.. somehow, the 'imageName' is being treated differently for the TCanvas.fillPattern.imageName vs. the TImage.imageName.
>
>
> regards.. Bruno
>
Sun, May 31 2015 4:10 AMPermanent Link

Rick

On 30/05/15 14:34, Bruno Larochelle wrote:
> I'm trying to draw using on the canvas using a pattern (image) :
>
> pntMain.canvas.fillStyle := dsPattern;
> pntMain.canvas.fillPattern.imageName := 'clouds.png';
> pntMain.canvas.fillPattern.repeatStyle := rsBoth;
> pntMain.canvas.fillRect(0,0,300,300);
>
> this gives an error at run-time saying 'clouds.png' not loaded
>
>

Have a look at TCanvasImage for pre-loading images to be used by the
canvas. It has an OnLoad event that you can use once the image has
completed loading.

--
Rick
Image