Board index » delphi » Copy a bitmap from a bitmap pointer

Copy a bitmap from a bitmap pointer

I have an application where I need to copy a bitmap which is passed as a
pointer - its from a C dll and the declaration is (BITMAP *pbmp)

I am using pBitmap in Delphi which means I can access the structure ok - but
I want to copy the bitmap into somthing like a delphi graphic control. Do I
need to use the Windows function CreateBitmapIndirect( *pbmp) - but what do
I do with the handle once I have it - I get lost at this point. The bitmap
is only monochrome - which I why I am using CreateBitmapIndirect - I seem to
remember this  is recommended for monochome.

Thanks in advance ,
Mike

 

Re:Copy a bitmap from a bitmap pointer


Not sure if I made it clear Jon - but the *pbmp is a Windows bitmap  - not a
Tbitmap - it doesn't seem to work and says invalid bitmap. Am I missing
something ?
Thanks for trying ,
Mike
Quote
"Jon Scott" <jescottNOS...@email.com> wrote in message

news:3c8932c9$1_1@dnews...
Quote
> You can do that with typecasting.  Here's an example that takes a pointer
of
> a bitmap and places it into a TImage control:

> procedure TForm1.Button1Click(Sender: TObject);
> var
>   BM: TBitmap;
>   pBitmap: pointer;
> begin
>   BM := TBitmap.Create;
>   try
>     BM.Assign(Image1.Picture.Bitmap);
>     pBitmap := @BM;
>     Image2.Picture.Bitmap.Assign(TBitmap(pBitmap^));
>   finally
>     BM.FreeImage;
>     FreeAndNil(BM);
>   end;
> end;

> --
> Thanks,
> Jon.

> "MikeBruce" <M...@heworthbookies.fsnet.co.uk> wrote in message
> news:3c891ff8_1@dnews...
> > I have an application where I need to copy a bitmap which is passed as a
> > pointer - its from a C dll and the declaration is (BITMAP *pbmp)

> > I am using pBitmap in Delphi which means I can access the structure ok -
> but
> > I want to copy the bitmap into somthing like a delphi graphic control.
Do
> I
> > need to use the Windows function CreateBitmapIndirect( *pbmp) - but what
> do
> > I do with the handle once I have it - I get lost at this point. The
bitmap
> > is only monochrome - which I why I am using CreateBitmapIndirect - I
seem
> to
> > remember this  is recommended for monochome.

> > Thanks in advance ,
> > Mike

Re:Copy a bitmap from a bitmap pointer


You can do that with typecasting.  Here's an example that takes a pointer of
a bitmap and places it into a TImage control:

procedure TForm1.Button1Click(Sender: TObject);
var
  BM: TBitmap;
  pBitmap: pointer;
begin
  BM := TBitmap.Create;
  try
    BM.Assign(Image1.Picture.Bitmap);
    pBitmap := @BM;
    Image2.Picture.Bitmap.Assign(TBitmap(pBitmap^));
  finally
    BM.FreeImage;
    FreeAndNil(BM);
  end;
end;

--
Thanks,
Jon.

Quote
"MikeBruce" <M...@heworthbookies.fsnet.co.uk> wrote in message

news:3c891ff8_1@dnews...
Quote
> I have an application where I need to copy a bitmap which is passed as a
> pointer - its from a C dll and the declaration is (BITMAP *pbmp)

> I am using pBitmap in Delphi which means I can access the structure ok -
but
> I want to copy the bitmap into somthing like a delphi graphic control. Do
I
> need to use the Windows function CreateBitmapIndirect( *pbmp) - but what
do
> I do with the handle once I have it - I get lost at this point. The bitmap
> is only monochrome - which I why I am using CreateBitmapIndirect - I seem
to
> remember this  is recommended for monochome.

> Thanks in advance ,
> Mike

Re:Copy a bitmap from a bitmap pointer


Create a new TBitmap and set the TBitmap handle to this handle of yours:
Handle := pbmp^;

"MikeBruce" <M...@heworthbookies.fsnet.co.uk> escreveu na mensagem
news:3c891ff8_1@dnews...

Quote
> I have an application where I need to copy a bitmap which is passed as a
> pointer - its from a C dll and the declaration is (BITMAP *pbmp)

> I am using pBitmap in Delphi which means I can access the structure ok -
but
> I want to copy the bitmap into somthing like a delphi graphic control. Do
I
> need to use the Windows function CreateBitmapIndirect( *pbmp) - but what
do
> I do with the handle once I have it - I get lost at this point. The bitmap
> is only monochrome - which I why I am using CreateBitmapIndirect - I seem
to
> remember this  is recommended for monochome.

> Thanks in advance ,
> Mike

Re:Copy a bitmap from a bitmap pointer


I think you need to use the CreateBitmapIndirect(..) function with a code
like this one:
pBmp: PBitmap;
Bmp: TBitmap;

Bmp := TBitmap.Create;
Bmp.Handle := CreateBitmapIndirect(pBmp^)

meaning you create the TBitmap object and use the CreateBitmapIndirect to
get your windows HBITMAP handle and then assign it to your Delphi object.

--
Liran Shahar
Com-N-Sense (www.com-n-sense.com)

Other Threads