panJames
asked on
Passing a bitmap to DLL using handle to it
Hello experts :-)
I need to pass a bitmap to a dll, edit it there and then send to back.
I know (thank you ziolko :-) ) how to do it using (Buffer : Pointer; StreamLength : Int64).
However, I was told that it is possible to pass a handle to bitmap to DLL and make it this way.
Question: how can I do it?
Polon
I need to pass a bitmap to a dll, edit it there and then send to back.
I know (thank you ziolko :-) ) how to do it using (Buffer : Pointer; StreamLength : Int64).
However, I was told that it is possible to pass a handle to bitmap to DLL and make it this way.
Question: how can I do it?
Polon
do you write the dll yourself?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I modified the contents of the button click event to draw to the second bitmap and show that both update...
procedure TForm1.Button1Click(Sender: TObject);
begin
Bitmap2.Handle := Bitmap1.Handle;
with Bitmap2, Canvas do
begin
MoveTo(0, 0);
LineTo(99, 99);
end;
PaintBox1.Invalidate;
PaintBox2.Invalidate;
end;
I'm afraid that's not what you looking for but that's best solution I've come up with
library BMPDLL;
uses
SysUtils,
Classes,
Windows,
Graphics;
{$R *.res}
procedure MakeColorAnalysis3(var Bitmap: HBITMAP);stdcall;
var bmp: TBitmap;
begin
bmp := TBitmap.Create;
try
bmp.Handle := Bitmap;
with TBitmap.Create do begin
Assign(bmp);
Canvas.MoveTo(0, 0);
Canvas.LineTo(256, 256);
Bitmap := Handle;
end;
finally
bmp.Free;
end;
end;
exports
MakeColorAnalysis3;
begin
end.
EXE:
interface
procedure MakeColorAnalysis3(var Bitmap: HBITMAP);stdcall;
implementation
procedure MakeColorAnalysis3;externa l 'bmpdll.dll' name 'MakeColorAnalysis3';
procedure TForm1.Button6Click(Sender : TObject);
var h: HBITMAP;
begin
h := Image1.Picture.Bitmap.Hand le;
MakeColorAnalysis3(h);
Image1.Picture.Bitmap.Hand le := h;
end;
ziolko.
library BMPDLL;
uses
SysUtils,
Classes,
Windows,
Graphics;
{$R *.res}
procedure MakeColorAnalysis3(var Bitmap: HBITMAP);stdcall;
var bmp: TBitmap;
begin
bmp := TBitmap.Create;
try
bmp.Handle := Bitmap;
with TBitmap.Create do begin
Assign(bmp);
Canvas.MoveTo(0, 0);
Canvas.LineTo(256, 256);
Bitmap := Handle;
end;
finally
bmp.Free;
end;
end;
exports
MakeColorAnalysis3;
begin
end.
EXE:
interface
procedure MakeColorAnalysis3(var Bitmap: HBITMAP);stdcall;
implementation
procedure MakeColorAnalysis3;externa
procedure TForm1.Button6Click(Sender
var h: HBITMAP;
begin
h := Image1.Picture.Bitmap.Hand
MakeColorAnalysis3(h);
Image1.Picture.Bitmap.Hand
end;
ziolko.
I've also found some C++ code that supposedly lets you access raw bmp bits represented by HBITMAP (so there's no need to create additional bmp in DLL and re-assign Handle on EXE side) but can't make it work all I got is scrambled image.
ziolko.
ziolko.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
with TmpBMP do begin
ReleaseHandle;
Assign(bmp);
Canvas.MoveTo(0, 0);
ziolko.
ReleaseHandle;
Assign(bmp);
Canvas.MoveTo(0, 0);
ziolko.
any progress on this one?
ziolko.
ziolko.