Recent

Author Topic: Canvas TextOUT  (Read 7739 times)

Cliff48

  • Jr. Member
  • **
  • Posts: 51
Canvas TextOUT
« on: May 04, 2015, 12:08:05 pm »
I have a BMP Loaded into a Timage.canvas.  I am trying to write text onto the image using TextOUT.  At the time it is written I see the text flash on the image , so i know I'm writing it correctly to the right place, but the text doesn't stay on the image.  I am sure its something stupid I have overlooked and hopefully more experienced programmers than me can give some clues were to look.

Thanks in advance
Laz Ver 1.4.0  FPC 2.6.4 SVN 48774
Win 7 Ultimate SP1
Intel I7-2600 CPU @  3.40GHZ 8GB Ram 64bit OS

Blaazen

  • Hero Member
  • *****
  • Posts: 2838
  • POKE 54296,15
    • Eye-Candy Controls
Re: Canvas TextOUT
« Reply #1 on: May 04, 2015, 01:25:32 pm »
There are two canvases in TImage: Image.canvas and Image.Picture.Bitmap.Canvas. The first is canvas just like any other, the second is canvas of loaded picture.
Lazarus 2.1.0 r63594 FPC 3.3.1 r40507 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

Cliff48

  • Jr. Member
  • **
  • Posts: 51
Re: Canvas TextOUT
« Reply #2 on: May 04, 2015, 01:30:45 pm »
Thanks, but i am not sure what that means to me.  I am guessing that I should Textout to the 2nd one?

Thx for quick response
Laz Ver 1.4.0  FPC 2.6.4 SVN 48774
Win 7 Ultimate SP1
Intel I7-2600 CPU @  3.40GHZ 8GB Ram 64bit OS

circular

  • Hero Member
  • *****
  • Posts: 3359
    • Personal webpage
Re: Canvas TextOUT
« Reply #3 on: May 04, 2015, 01:32:27 pm »
You can textout on the second one, but only once. After loading the picture, or in FormCreate event. It will then stay on the image.
Conscience is the debugger of the mind

Cliff48

  • Jr. Member
  • **
  • Posts: 51
Re: Canvas TextOUT
« Reply #4 on: May 04, 2015, 02:21:55 pm »
You can textout on the second one, but only once. After loading the picture, or in FormCreate event. It will then stay on the image.

Thanks, but i'm still having problems.
With Textout, i am now just getting a rectangular shape in the colour of the windows panel coming yhru my image.  Thats prolly something wrong in the style I am setting.. i guess.
Using TextRect, my image disappears and is replaced by the text. I have googled everything i can think of about writing text onto an image and the only references I can find are pointing to other packages.  Surely it cant be that hard to write some text on an image.
Laz Ver 1.4.0  FPC 2.6.4 SVN 48774
Win 7 Ultimate SP1
Intel I7-2600 CPU @  3.40GHZ 8GB Ram 64bit OS

Blaazen

  • Hero Member
  • *****
  • Posts: 2838
  • POKE 54296,15
    • Eye-Candy Controls
Re: Canvas TextOUT
« Reply #5 on: May 04, 2015, 02:36:38 pm »
Try
Code: [Select]
...Canvas.Brush.Style:=bsClear;
Lazarus 2.1.0 r63594 FPC 3.3.1 r40507 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

Cliff48

  • Jr. Member
  • **
  • Posts: 51
Re: Canvas TextOUT
« Reply #6 on: May 04, 2015, 03:25:07 pm »
Try
Code: [Select]
...Canvas.Brush.Style:=bsClear;

Thanks Blaazen, i do have that.

I think i'll just revert to the old days and use some API calls to actually update the BMP image, after all, that is the result I ultimately want.
Laz Ver 1.4.0  FPC 2.6.4 SVN 48774
Win 7 Ultimate SP1
Intel I7-2600 CPU @  3.40GHZ 8GB Ram 64bit OS

Cliff48

  • Jr. Member
  • **
  • Posts: 51
[SOLVED] Re: Canvas TextOUT
« Reply #7 on: May 07, 2015, 10:15:22 pm »
Looking around some more I found a simple solution that works for my needs.

load image to a Tbitmap

display that image on Timage

make change to tbitmap with textout or textrect
show changed image in Timage

save tbitmap to file.

Thanks to those that attempted to help, but didnt understand my question/requirement.
Laz Ver 1.4.0  FPC 2.6.4 SVN 48774
Win 7 Ultimate SP1
Intel I7-2600 CPU @  3.40GHZ 8GB Ram 64bit OS

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: Canvas TextOUT
« Reply #8 on: May 07, 2015, 10:49:43 pm »
It seems that there is a problem here, indeed. This code:

Code: [Select]
with image1.{Picture.Bitmap.}Canvas do
  begin
    Brush.Style := bsClear;
    Font.Color := clBlack;
    TextOut(0,0, 'abc');
  end;   

seems to have different result than this one:

Code: [Select]
with image1.Picture.Bitmap.Canvas do
  begin
    Brush.Style := bsClear;
    Font.Color := clBlack;
    TextOut(0,0, 'abc');
  end;   

circular

  • Hero Member
  • *****
  • Posts: 3359
    • Personal webpage
Re: Canvas TextOUT
« Reply #9 on: May 08, 2015, 07:43:06 pm »
Well that's not surprising. Image1.Canvas is the window surface, whereas image1.Picture.Bitmap.Canvas is the surface of the bitmap.
Conscience is the debugger of the mind

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: Canvas TextOUT
« Reply #10 on: May 08, 2015, 08:02:20 pm »
Text is written, but why they are of a different colors?

Eugene Loza

  • Hero Member
  • *****
  • Posts: 566
    • My "almost daily" development blog
Re: Canvas TextOUT
« Reply #11 on: May 08, 2015, 08:42:25 pm »
I often do it in a 'more stupid way'. I use a temporary TJPEG or similar object to load the image into memory and then TCanvas.CopyRect to copy the image to the visible canvas. That leaves me lot's of freedom to scale/zoom, process the image. &Never had any problems with that stuff.
Lazarus 1.9 + FPC 3.1.1 Debian Jessie 64 bit.

My Free and Open Source games in Lazarus/FreePascal/CastleGameEngine:
https://decoherence.itch.io/
(and some ancient games in Turbo Pascal too)
Sources are here: https://github.com/eugeneloza?tab=repositories

User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
Re: [SOLVED] Re: Canvas TextOUT
« Reply #12 on: May 08, 2015, 09:40:16 pm »
load image to a Tbitmap

display that image on Timage

make change to tbitmap with textout or textrect
show changed image in Timage

save tbitmap to file.
For sequence like that, i would use TPicture. Roughly something like:
Code: [Select]
var pic: TPicture;
begin
  pic:=TPicture.Create;
  pic.LoadFromFile('background.jpg');
  // Don't need to load anything if want just single color.
  // In those cases set the image size and then fill with color.
  pic.Canvas.Font... brush... TextOut...
  pic.SaveToFile('saved.jpg');
  pic.Free;
end;

circular

  • Hero Member
  • *****
  • Posts: 3359
    • Personal webpage
Re: Canvas TextOUT
« Reply #13 on: May 08, 2015, 11:36:41 pm »
Text is written, but why they are of a different colors?
Ah ok. Any screenshot?
Conscience is the debugger of the mind

 

TinyPortal © 2005-2018