Results 1 to 4 of 4

Thread: Fonts & TImage

  1. #1
    Join Date
    Dec 2010
    Posts
    89
    Mentioned
    4 Post(s)
    Quoted
    8 Post(s)

    Default Fonts & TImage

    Here's a quick question that I hope that can be solved quickly.
    How would I write black text on a Canvas? My current code looks like this.

    Simba Code:
    program new;
    var
      Buffer: Integer;

    procedure DrawOnBuffer;
    var
      text, Width, Height: Integer;
      Font: TFont;

    begin
      Buffer:= BitmapFromString(200, 200, '');
      RectangleBitmap(Buffer, IntToBox(0, 0, 199, 199), 16777215);  //Comment this line
                                                                    //and you will see text
      Font := TFont.Create;
      Font.Name := 'Courier New';
      Font.Size := 10;
      Font.Color:= 0;
      Font.Style := [];
      LoadSystemFont(Font,'test');


      text:= BitmapFromText('Hello', 'test');
      GetBitmapSize(text, Width, Height);
      SetTransparentcolor (text, clBlack);
      FastDrawTransparent(round ((200 * 0.5) - (Width/ 2)), 12, text, Buffer);
      FreeBitmap(text);
      Font.free;
    end;

    procedure CreateCanvas;
    begin
      DisplayDebugImgWindow(200, 200);
      DrawOnBuffer;
      DrawBitmapDebugImg(Buffer);
      FreeBitmap(Buffer);
    end;

    begin
      SetupSRL;
      CreateCanvas;
    end.

    Is there anyway where I can turn the font color black? Also...
    Out of curiousity, is there a way to create transparent colors for TImages (bitmaps) that are on a form?
    Last edited by Valithor; 06-27-2013 at 02:37 AM.

  2. #2
    Join Date
    May 2013
    Posts
    23
    Mentioned
    0 Post(s)
    Quoted
    5 Post(s)

    Default

    Quote Originally Posted by Valithor View Post
    Here's a quick question that I hope that can be solved quickly.
    How would I write black text on a Canvas? My current code looks like this.

    Simba Code:
    program new;
    var
      Buffer: Integer;

    procedure DrawOnBuffer;
    var
      text, Width, Height: Integer;
      Font: TFont;

    begin
      Buffer:= BitmapFromString(200, 200, '');
      RectangleBitmap(Buffer, IntToBox(0, 0, 199, 199), 16777215);  //Comment this line
                                                                    //and you will see text
      Font := TFont.Create;
      Font.Name := 'Courier New';
      Font.Size := 10;
      Font.Color:= 0;
      Font.Style := [];
      LoadSystemFont(Font,'test');


      text:= BitmapFromText('Hello', 'test');
      GetBitmapSize(text, Width, Height);
      SetTransparentcolor (text, clBlack);
      FastDrawTransparent(round ((200 * 0.5) - (Width/ 2)), 12, text, Buffer);
      FreeBitmap(text);
      Font.free;
    end;

    procedure CreateCanvas;
    begin
      DisplayDebugImgWindow(200, 200);
      DrawOnBuffer;
      DrawBitmapDebugImg(Buffer);
      FreeBitmap(Buffer);
    end;

    begin
      SetupSRL;
      CreateCanvas;
    end.

    Is there anyway where I can turn the font color black? Also...
    Out of curiousity, is there a way to create transparent colors for TImages (bitmaps) that are on a form?
    Hm.. i was also wondering how to make transparent images on forms. I think you can just set the image the same colour as the background or another way which i tried was to set the part of the image you want transparent to the same image on the background of your form. Maybe someone knows a better way to do it. Tell me if script below works.

    Click start bot once and wait for the monkey to disappear. you can also click close bot and a picture appears.
    test.rar
    Last edited by ActualNoob; 06-28-2013 at 07:48 PM.

  3. #3
    Join Date
    Dec 2010
    Posts
    89
    Mentioned
    4 Post(s)
    Quoted
    8 Post(s)

    Default

    Quote Originally Posted by ActualNoob View Post
    Hm.. i was also wondering how to make transparent images on forms. I think you can just set the image the same colour as the background or another way which i tried was to set the part of the image you want transparent to the same image on the background of your form. Maybe someone knows a better way to do it.
    Actually, I think that is a pretty good work around! The only issue that I found is that some of your coordinates may be off. Because I tend to get a lot of distortion when your images appear. I'll have to look through your code to see if I can improve upon it but that seems to work (granted that we can fix the distortion issue). Image provided.



    Also, you have A LOT of variables that are never called, and you don't free some bitmaps. Debug will read...

    Progress Report:
    The following bitmaps were not freed: [0, 1, 2].
    Sometimes the "buffer" and Bitmap[5] aren't freed. One final note that should be considered. If there is a window on top of the form then, it will also grab parts of that window and print it on your form. Do you know of any way to take from ONLY the form?

    EDIT: Actually, it looks like the above mentioned distortion comes from the way you are drawing the bitmaps on the Form. I was having a similar issue earlier while experimenting with Canvases. If you draw a bitmap on a canvas you'll get multiple layered copies. Not exactly the desired effect.

    This can be seen from lines 270 to 283.

    EDIT 2: Though, the that method would work excellently if you wanted to print a static (not moving) image. Like you do with your "character" image. Your "GetImg()" function works great, though if you want it to print "seamlessly" you'll need to change the final line to:
    Simba Code:
    DrawBitmap(buffer, dsgnForm.CANVAS, x - 4, y - 30);
    Last edited by Valithor; 07-03-2013 at 05:11 PM.

  4. #4
    Join Date
    May 2013
    Posts
    23
    Mentioned
    0 Post(s)
    Quoted
    5 Post(s)

    Default

    Thanks for testing it out and giving me some advice. I have only begun coding for 2-3 weeks so iam still trying stuff out on my own so my code is very messy iam glad you could read it though. I was afraid this would happen. The distortions are caused by you using a different computer theme than mine( the icons on the top cause a different sized bar), so the offset x-4, y-30 are different to mine.

    Code:
    DrawBitmap(buffer, dsgnForm.CANVAS, x +dsgnForm.ClientWidth - dsgnForm.Width , y + dsgnForm.ClientHeight- dsgnForm.Height);
    The above code should be correct, but for some reason they(dsgnForm.clientWidth and dsgnForm.Width) return the same value which isnt supposed to happen. I tried a work around and i cleaned up unused variables and freed the bitmaps. I also took your advice and it draws it onto a TImage now so if you drag a window on top it wont disappear.

    Sometimes the "buffer" and Bitmap[5] aren't freed. One final note that should be considered. If there is a window on top of the form then, it will also grab parts of that window and print it on your form. Do you know of any way to take from ONLY the form?
    I will look at it. for some reason it still does it.

    attached wrong file

    gui1.rar
    Last edited by ActualNoob; 07-03-2013 at 08:14 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •