Results 1 to 3 of 3

Thread: TMufasa To TBitmap Directly

  1. #1
    Join Date
    Feb 2011
    Location
    The Future.
    Posts
    5,600
    Mentioned
    396 Post(s)
    Quoted
    1598 Post(s)

    Default TMufasa To TBitmap Directly

    Is there a way to go from TMufasaBitmap to TBitmap directly without it creating a middleman copy? OR is there a way to go from TBitmap to Integer Handle bmp's Directly?

    Example of what I do not want:

    Simba Code:
    {$I SRL/SRL.Simba}
    {$I SRL/SRL/Misc/Debug.Simba}

    Procedure MiddleMan;
    var
      TM: TMufasaBitmap;
      TB: TBitmap;
    begin
      TM := TMufasaBitmap.create;

      TB := TBitmap.Create;
      TB.Width := 200;
      TB.Height := 200;
      TB.Canvas.Pen.COLOR := 16777215;
      TB.Canvas.Rectangle(0, 0, 100, 100);
      TM.LoadFromTBitmap(TB);
      TB.Free;
      DebugBitmap(TM.Index);
      TM.Free;
    end;

    Procedure Wanted;
    var
      TM: TMufasaBitmap;
    begin
      TM := TMufasaBitmap.create;
      SetBitmapSize(TM.Index, 200, 200);
      TM.ToTBitmap.Canvas.Pen.Color := 16777215;
      TM.ToTBitmap.Canvas.Rectangle(0, 0, 100, 100);
      DebugBitmap(TM.Index);
      TM.Free;
    end;

    Procedure SimilarWanted;
    var
      BMP: Integer;
    begin
      BMP := CreateBitmap(200, 200);
      GetMufasaBitmap(BMP).Rectangle(IntToBox(0, 0, 100, 100), 255);
      DebugBitmap(BMP);
      FreeBitmap(BMP);
    end;

    begin
      Wanted;           //Draws Nothing..
      Wait(1500);
      MiddleMan;        //Draws A White Box..
      Wait(1500);
      SimilarWanted;    //Draws A Red Box..
    end.

    See the difference? The first uses a middleman TBitmap and it works find and dandy. The second does not use a middle man but guess what? The second is a memory leak since the TBitmap created is from raw data but is not freed. We all saw what happens before when you assign to a result directly.
    The third uses an integer handle which is just a property of the mufasa class. All bitmaps are essentially TMufasaBitmap.Index. They're swapable from Int To TMufasa To Int. This is not the case with TBitmap to anything To TBitmap. Anyone know how to do it?

    Why? Because if I draw on the TBitmap after doing ToTBitmap, the TMufasa will not have that drawing on it's canvas unless I load it from a separate TBitmap.

    I also want to know how to index a TBitmap. It's not the same as TBitmap.Handle. What use is the handle if I can't use it?

    Mufasa's class has TMufasaBitmap.index which is the same as doing BMP: Integer; That's perfect. But TBitmap has no such thing :S
    Last edited by Brandon; 07-07-2012 at 07:11 AM.
    I am Ggzz..
    Hackintosher

  2. #2
    Join Date
    Oct 2006
    Location
    Netherlands
    Posts
    3,285
    Mentioned
    105 Post(s)
    Quoted
    494 Post(s)

    Default

    Simba Code:
    program new;

    Procedure MiddleMan;
    var
      TM: TMufasaBitmap;
      TB: TBitmap;
    begin
      TM := TMufasaBitmap.create;

      TB := TM.ToTBitmap;
      TB.Width := 200;
      TB.Height := 200;
      TB.Canvas.Pen.COLOR := 3114851;
      TB.Canvas.Brush.Color := 10132122;
      TB.Canvas.Rectangle(0, 0, 100, 100);
      TM.LoadFromTBitmap(TB);
      TB.Free;
      //DebugBitmap(TM.Index);
      //DisplayDebugImgWindow(200,200);
      //DrawBitmapDebugImg(TM.Index);
      TM.Free;
    end;

    var
      i:Integer;
    begin
      For i := 0 to 1000000 do
       MiddleMan;
    end.
    Working on: Tithe Farmer

  3. #3
    Join Date
    Dec 2006
    Location
    Sydney, New South Wales, Australia
    Posts
    4,603
    Mentioned
    15 Post(s)
    Quoted
    42 Post(s)

    Default

    Simba Code:
    var
      Bitmap: TBitmap;

    begin
      Bitmap.Assign(GetMufasaBitmap(I).ToTBitmap);
    end.

    You can also do something like:
    Simba Code:
    var
      Bitmap: TBitmap;

    begin
      Bitmap := TBitmap.Create;
      Bitmap.Assign(GetMufasaBitmap(BitmapFromString(5, 5, 'abcdef<bmphere>==')).ToTBitmap);
    end.
    ... if you wish.

    And, Simba just stores all of its bitmaps loaded from within the script via methods such as BitmapFromString into an array of TMufasaBitmap. The return code of BitmapFromString is simply the index of that array.
    Last edited by Daniel; 07-07-2012 at 08:29 AM.
    You may contact me with any concerns you have.
    Are you a victim of harassment? Please notify me or any other staff member.

    | SRL Community Rules | SRL Live Help & Chat | Setting up Simba | F.A.Q's |

Thread Information

Users Browsing this Thread

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

Posting Permissions

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