Results 1 to 5 of 5

Thread: bitmap(integer) to Tcanvas ?

  1. #1
    Join Date
    Oct 2011
    Posts
    805
    Mentioned
    21 Post(s)
    Quoted
    152 Post(s)

    Default bitmap(integer) to Tcanvas ?

    I have two bitmaps (integer). I want to draw bitmap_2 inside bitmap_1. I find function DrawBitmap(Bmp:integer ; Dest : Tcanvas ; x,y : integer);

    But destination is in format Tcanvas. how to convert bmp(integer) to Tcanvas?

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

    Default

    Simba Code:
    var
      BMP, X, Y: Integer;
      TBMP: TBitmap;

    begin
      BMP:= CreateBitmap(10, 10);
      TBMP:= GetMufasaBitmap(BMP).ToTBitmap;
      DrawBitmap(BMP, TBMP.Canvas, X, Y);
      FreeBitmap(BMP);
      TBMP.Free;
    end.
    I am Ggzz..
    Hackintosher

  3. #3
    Join Date
    Oct 2011
    Posts
    805
    Mentioned
    21 Post(s)
    Quoted
    152 Post(s)

    Default

    And how to convert it back to bmp?

    I tried:

    Simba Code:
    var
      BMP, BMP2, X, Y: Integer;
      TBMP: TBitmap;

      MufasaBMP :TMufasaBitmap;

    begin
      BMP:= CreateBitmap(10, 10);

      BMP2:= CreateBitmap(2, 2);

      TBMP:= GetMufasaBitmap(BMP).ToTBitmap;
      DrawBitmap(BMP2, TBMP.Canvas, X, Y);

      MufasaBMP.LoadFromTBitmap(TBMP);   // error here
      BMP:=BitmapFromString(w,h,MufasaBMP.ToString);
      DebugBitmap(BMP);

      FreeBitmap(BMP);
      TBMP.Free;
    end.
    but
    Code:
    Error: Null Pointer Exception at line 32

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

    Default

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

    var
      BMP, BMP2, X, Y, BMPH, BMPW: Integer;
      TBMP: TBitmap;
      MufasaBMP :TMufasaBitmap;

    begin
      BMPH:= 10;
      BMPW:= 10;       //Width and height respectfully.

      BMP:= CreateBitmap(BMPH, BMPW); //You know this can be a string right? Such as BitmapFromString..
      BMP2:= CreateBitmap(BMPH, BMPW);  //Same as above..

      TBMP:= GetMufasaBitmap(BMP).ToTBitmap;
      DrawBitmap(BMP2, TBMP.Canvas, X, Y);

      MufasaBMP:= GetMufasaBitmap(BMP);   //Can probably swap this with a TMufasaBitmap.Create.. No difference I believe.
      MufasaBMP.LoadFromTBitmap(TBMP);
      BMP:= BitmapFromString(BMPW, BMPH, MufasaBMP.ToString);
      DebugBitmap(BMP);

      FreeBitmap(BMP);
      FreeBitmap(BMP2);
      TBMP.Free;
      MufasaBMP.Free;
    end.
    I am Ggzz..
    Hackintosher

  5. #5
    Join Date
    Oct 2011
    Posts
    805
    Mentioned
    21 Post(s)
    Quoted
    152 Post(s)

    Default

    Tyvm.

    I made procedure to not muck with it anymore.

    Simba Code:
    procedure DrawBmpInBmp(var Bmp ,DestBmp :integer;  x , y :integer );
    var
    MufasaBMP :TMufasaBitmap;
    Tbmp : Tbitmap;
    begin
       Tbmp:= GetMufasaBitmap(DestBmp).ToTBitmap;
       DrawBitmap(bmp,Tbmp.canvas,x,y);
       MufasaBMP:= GetMufasaBitmap(DestBmp);
       MufasaBMP.LoadFromTBitmap(Tbmp);
       DestBmp:=BitmapFromString(MufasaBMP.Width, MufasaBMP.Height ,MufasaBMP.ToString);
       Tbmp.Free;
       MufasaBMP.Free;
    end;

    Test:
    Put cross on code.

    Simba Code:
    program Test;

      {$i srl/srl.simba}
      {$I srl/srl/misc/debug.simba}

    var                                             //            //
      w, h: integer;

      bmpx ,bmpx2: Integer;
                                                     //               //
      TPA ,bTPA: TPointArray;

      bound :tbox;

    procedure DrawBmpInBmp(var Bmp ,DestBmp :integer;  x , y :integer );
    var
    MufasaBMP :TMufasaBitmap;
    Tbmp : Tbitmap;
    begin
       Tbmp:= GetMufasaBitmap(DestBmp).ToTBitmap;
       DrawBitmap(bmp,Tbmp.canvas,x,y);
       MufasaBMP:= GetMufasaBitmap(DestBmp);
       MufasaBMP.LoadFromTBitmap(Tbmp);
       DestBmp:=BitmapFromString(MufasaBMP.Width, MufasaBMP.Height ,MufasaBMP.ToString);
       Tbmp.Free;
       MufasaBMP.Free;
    end;

    begin
      GetClientDimensions(w,h);
      bmpx:= CreateBitmap(w, h);
      CopyClientToBitmap(bmpx, 0, 0, w -1, h -1);
      FindColorstolerance(TPA,16711680,msx1,msy1,w-1,h-1,5);
      bound :=GetTpaBounds(TPA);

      bmpx2:= CreateBitmap(1,1);
      bmpx2:= Bitmapfromclient(bound.x1,bound.y1,bound.x2,bound.y2);
      bmpx2 := posterizebitmap(bmpx2,200);

      //now we want to draw bmpx2 inside bmpx

      DrawBmpInBmp(bmpx2, bmpx, bound.x1, bound.y1 );


      DebugBitmap(BMPX);
      FreeBitmap(BMPX);
      FreeBitmap(BMPX2);

    end.
    Code:
    The following bitmaps were not freed: [1, 2]
    Works good despite of little memory leak.Anyway

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
  •