Log in

View Full Version : TMufasa To TBitmap Directly



Brandon
07-07-2012, 06:52 AM
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:


{$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

masterBB
07-07-2012, 08:24 AM
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.

Daniel
07-07-2012, 08:26 AM
var
Bitmap: TBitmap;

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


You can also do something like:

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.