SRL Archive - Help and Support

How do I handle bitmaps in a plugin and make them compatible with SCAR?


R0b0t1

2007-10-13 21:55:06

Wait! That means you! Don't you dare mention the testplugin image example, thats not what mines like.



So, if I want to except a bitmap as a parameter in a SCAR <-> Delphi plugin, whats its type? Does Delphi take bitmap values as integers?


And in case your IQ is less than your penis' size in inches, I mean like this:


function BMPshizz(TheQuestionParameter: TBitmap): Boolean or somthing;
{or like this}
function BMPshiz2(TheQuestionParameter: Integer): Boolean or something;

Jason2gs

2007-10-14 00:33:44

Now that's a good question…

My guess would be to use TBitmap for both SCAR and Delphi. When you're in the plugin, use TBitmap.Canvas.CopyRect to copy the canvas imported from SCAR, into the plugin.

In SCAR:

program New;

var
Bmp: Integer;
MyBmp: TBitmap;

begin
MyBmp := TBitmap.Create;
MyBmp.Height := 250;
MyBmp.Width := 250;
Bmp := BitmapFromString(250, 250, '');
CopyCanvas(GetBitmapCanvas(Bmp), MyBmp.Canvas, 0, 0, 250, 250, 0, 0, 250, 250);
end.

In Delphi:

function BMPThing(TheQuestionParameter: TBitmap): Boolean; stdcall;
var
MyBmp: TBitmap;
W, H: Integer;
begin
MyBmp := TBitmap.Create;
W := TheQuestionParameter.Width;
H := TheQuestionParameter.Height;
MyBmp.Canvas.CopyRect(Rect(0, 0, W, H), TheQuestionParameter.Canvas, Rect(0, 0, W, H));
end;

Makes sense to me at least :)

Markus

2007-10-14 01:56:01

Import getbitmapdc in the plugin, then bitblt it to the bitmap.

mastaraymond

2007-10-14 04:55:27

Send the handle to the plugin with this: GetBitmapCanvas(Bitmap).Handle. Then make a TBitmap in your procedure bitblt the imported handle on the TBitmap.Handle. Edit the TBitmap, bitblt the TBitmap handle on the Imported handle, and voila your done.


~Raymond

R0b0t1

2007-10-14 13:36:30

Ok, thanks for the information. The reason it got me wondering was because I though scar couldn't to TBitmaps.

The only problem though will be how to handle it once its in SCAR… But I just got an Idea - proofread it please?


This kinda relies on the fact that bitmaps are integers in SCAR…
DELPHI -

function DoWithBitmap(TheBitmapzor: Integer): Integer; overload; stdcall; //Is it overload or virtual?
begin
TheBitmapzor.Canvas // draw or something...//
Result:= TheBitmapzor;
end;

function DoWithBitmap(TheBitmapzor: TBitmap): TBitmap; overload; stdcall;
begin
//do something else...
Result:= TheBitmapzor;
end;

and in SCAR, you could call either, but with a Tbitmap, or and integer.

mastaraymond

2007-10-14 13:42:23

From: R0b0t1
Ok, thanks for the information. The reason it got me wondering was because I though scar couldn't to TBitmaps.

The only problem though will be how to handle it once its in SCAR… But I just got an Idea - proofread it please?


This kinda relies on the fact that bitmaps are integers in SCAR…
DELPHI -

function DoWithBitmap(TheBitmapzor: Integer): Integer; overload; stdcall; //Is it overload or virtual?
begin
TheBitmapzor.Canvas // draw or something...//
Result:= TheBitmapzor;
end;

function DoWithBitmap(TheBitmapzor: TBitmap): TBitmap; overload; stdcall;
begin
//do something else...
Result:= TheBitmapzor;
end;

and in SCAR, you could call either, but with a Tbitmap, or and integer.
Hmm, don't use TBitmaps, it sucks…. There not compatible just use GetBitmapCanvas(Bitmap).Handle, the handle is universal. Btw if you noticed, the first bitmap you declare gets number1, the second number 2, the tirth number 4 etc… Just make a parameter: DC : HDC, or something like that ;).

R0b0t1

2007-10-14 14:21:31

Sorry for being an idiot, but how do I manipulate a BMP from its handle?

mastaraymond

2007-10-14 15:09:51

From: R0b0t1
Sorry for being an idiot, but how do I manipulate a BMP from its handle?

Well, i used TImage, tbh ^^.
In delphi:
var
C : Tbitmap;
begin;
C := TImage.Create;
BitBlt(C.Canvas.Handle, 0, 0, W, H, DC FROM SCAR BITMAP, 0, 0, SRCCOPY);
your function...
BitBlt(DC FROM SCAR BITMAP, 0, 0, W, H, C.Canvas.Handle, 0, 0, SRCCOPY);
end;

Like this?

R0b0t1

2007-10-14 15:41:13

ahhh…. Ok. I still had to google BitBlt, but that helped :).



EDIT: Uhmmm… One last thing… Does TImage give access to the scanlines?

mastaraymond

2007-10-14 16:06:11

From: R0b0t1
ahhh…. Ok. I still had to google BitBlt, but that helped :).



EDIT: Uhmmm… One last thing… Does TImage give access to the scanlines?

Yeah i think it does, G.Picture.Bitmap.ScanLine…. Maybe TBitmap have got a canvas to, im not sure but if it does, you can do C := TBitmap.Create;
Bitblt( C.Canvas.Handle etc..);
And use C.Scanline… Im not sure, check it out ^^.

R0b0t1

2007-10-14 16:33:16

No wait! Not last thing! How can I access bitmap properties from the DC? I can;t find it on google.

mastaraymond

2007-10-14 17:28:01

From: R0b0t1
No wait! Not last thing! How can I access bitmap properties from the DC? I can;t find it on google.
Like what? Basicly what you do is, you copy the bitmap you made in scar onto the bitmap made in delphi then you edit the bitmap and you copy it back…

R0b0t1

2007-10-14 18:45:04

Yeah… But don't I need the width/height? Pr does it just go over with it?

mastaraymond

2007-10-15 01:39:35

From: R0b0t1
Yeah… But don't I need the width/height? Pr does it just go over with it?
You do need them.. Maybe you can send the through as an paramter ^^.

Jason2gs

2007-10-15 17:38:55

Wouldn't the width and height go along too if he just declared TBitmap as the parameter?

BenLand100

2007-10-15 19:04:43

You need to look up Windows GDI at msdn, since device context (DC) manipulation is defined there. To get the width and height, you need to get the currently selected HBITMAP out of the HDC, and then fill the BITMAP data structure from the HBITMAP. C++ code for it:

BITMAP __stdcall bmpdata(int hdc) {
HBITMAP hbitmap = (HBITMAP) GetCurrentObject((HDC)hdc, OBJ_BITMAP);
BITMAP bmp;
GetObject((HBITMAP)hbitmap,sizeof(BITMAP),&bmp);
if (bmp.bmBits == NULL) throw 1; //This checks if its a memory bitmap
return bmp;
}

The returned BITMAP object has a width and height parameter, as well as other info about the bitmap.

R0b0t1

2007-10-15 21:58:39

You know, I might give up delphi plugins because C++ is so awesome.

mastaraymond

2007-10-25 15:51:44

From: R0b0t1
You know, I might give up delphi plugins because C++ is so awesome.

You can do this in delphi to, easy.. Just api call the GetCurrentObject function ;).