### Bookstore

 Computer Math and Games in Pascal Lazarus, the complete guide (only a few left)

### Author Topic: BGRABitmap 2DCanvas with scale  (Read 684 times)

#### hosune7845

• Full Member
• Posts: 153
##### BGRABitmap 2DCanvas with scale
« on: March 23, 2017, 09:50:15 am »
Hello.

I drew vector images with TBGRABitmap.Canvas2D.FillText

It works fine. but TBGRABitmap.Canvas2D.scale function makes position error.

I attached two images with different scale.

Here's code

1. image 1.bmp
Code: Pascal  [Select]
1.   with aBGRABitmap.Canvas2D do
2.   begin
3.     FontEmHeight := 30;
4.     FontName     := 'Arial';
5.     FontStyle    := [];
6.     Antialiasing := True;
7.     FillStyle(BGRABlack);
8.     TextBaseline := 'top';
9.
10.     FillText('123456', 100 ,50);
11.   end;
12.

2. image 2.bmp
Code: Pascal  [Select]
1.   with aBGRABitmap.Canvas2D do
2.   begin
3.     Scale(1/5, 5);
4.     FontEmHeight := 30;
5.     FontName     := 'Arial';
6.     FontStyle    := [];
7.     Antialiasing := True;
8.     FillStyle(BGRABlack);
9.     TextBaseline := 'top';
10.
11.     FillText('123456', 100 ,50);
12.     Scale(5, 1/5);
13.   end;
14.

Anyone knows why the text position different?
« Last Edit: March 23, 2017, 09:56:23 am by hosune7845 »

#### circular

• Hero Member
• Posts: 2594
##### Re: BGRABitmap 2DCanvas with scale
« Reply #1 on: March 24, 2017, 06:17:12 am »
It is normal. The scaling applies to all coordinates. If you want the text to be at the pixel (100,50), then you need to do:
Code: Pascal  [Select]
1. translate(100,50);
2. scale(5,1/5); //for example
3. FillText('123456', 0,0);
4. resetTransform;
5.
Conscience is the debugger of the mind

#### hosune7845

• Full Member
• Posts: 153
##### Re: BGRABitmap 2DCanvas with scale
« Reply #2 on: March 24, 2017, 08:52:05 am »
It is normal. The scaling applies to all coordinates. If you want the text to be at the pixel (100,50), then you need to do:
Code: Pascal  [Select]
1. translate(100,50);
2. scale(5,1/5); //for example
3. FillText('123456', 0,0);
4. resetTransform;
5.

Thank you.

That works fine for me.

#### circular

• Hero Member
• Posts: 2594
##### Re: BGRABitmap 2DCanvas with scale
« Reply #3 on: March 24, 2017, 09:21:41 am »
Cool.

You're welcome.
Conscience is the debugger of the mind