SRL Archive - OSR Help

bitmap(integer) to Tcanvas ?


bg5

2012-01-16 12:50:29

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?

Brandon

2012-01-16 13:37:17


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.

bg5

2012-01-16 14:40:01

And how to convert it back to bmp?

I tried:

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
Error: Null Pointer Exception at line 32

Brandon

2012-01-16 14:58:36


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.

bg5

2012-01-16 16:10:08

Tyvm.

I made procedure to not muck with it anymore. :)

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.

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.
The following bitmaps were not freed: [1, 2]
Works good despite of little memory leak.:shifty:Anyway