Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8157515
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T17:18:46+00:00 2026-06-06T17:18:46+00:00

I would like to convert a TBitMap to a PBitMap in KOL. I tried

  • 0

I would like to convert a TBitMap to a PBitMap in KOL.

I tried this but I get a black picture as an output:

function TbitMapToPBitMap (bitmap : TBitMap) : PbitMap;
begin
 result := NIL;
 if Assigned(bitmap) then begin
  result := NewBitmap(bitmap.Width, bitmap.Height);
  result.Draw(bitmap.Canvas.Handle, bitmap.Width, bitmap.Height);
 end;
end;

Any idea what’s wrong with it? I am using Delphi7.

Thank you for your help.

EDIT: New CODE:

function TbitMapToPBitMap (const src : TBitMap; var dest : PBitMap) : Bool; 
begin
 result := false;
 if (( Assigned(src) ) and ( Assigned (dest) )) then begin
 dest.Draw(src.Canvas.Handle, src.Width, src.Height);
 result := true;
 end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
 TBitMapTest : TBitMap;
 PBitMapTest : PBitMap;
begin
 TBitMapTest := TBitMap.Create;
 TBitMapTest.LoadFromFile ('C:\test.bmp');
 PBitMapTest := NewBitMap (TBitMapTest.Width, TBitMapTest.Height);
 TbitMapToPBitMap (TBitMapTest, PBitMapTest);
 PBitMapTest.SaveToFile ('C:\test2.bmp');
 PBitMapTest.Free;
 TBitMapTest.Free;
end;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T17:18:48+00:00Added an answer on June 6, 2026 at 5:18 pm

    To answer your question why are your target images black; it’s because you were drawing those target images to source and black they were because the NewBitmap initializes images to black.

    How to copy or convert if you want a TBitmap to KOL PBitmap I found only one way (maybe I missed such function in KOL, but even if so, the method used in the following code is very efficient). You can use the Windows GDI function for bit-block transfer, the BitBlt, which just copies the specified area from one canvas to another.

    The following code, when you click on the button creates the VCL and KOL bitmap instances, loads the image to a VCL bitmap, call the VCL to KOL bitmap copy function and if this function succeed, draw the KOL bitmap to the form canvas and free both bitmap instances:

    uses
      Graphics, KOL;
    
    function CopyBitmapToKOL(Source: Graphics.TBitmap; Target: PBitmap): Boolean;
    begin
      Result := False;
      if Assigned(Source) and Assigned(Target) then
      begin
        Result := BitBlt(Target.Canvas.Handle, 0, 0, Source.Width, Source.Height,
          Source.Canvas.Handle, 0, 0, SRCCOPY);
      end;
    end;
    
    procedure TForm1.Button1Click(Sender: TObject);
    var
      KOLBitmap: PBitmap;
      VCLBitmap: Graphics.TBitmap;
    begin
      VCLBitmap := Graphics.TBitmap.Create;
      try
        VCLBitmap.LoadFromFile('d:\CGLIn.bmp');
        KOLBitmap := NewBitmap(VCLBitmap.Width, VCLBitmap.Height);
        try
          if CopyBitmapToKOL(VCLBitmap, KOLBitmap) then
            KOLBitmap.Draw(Canvas.Handle, 0, 0);
        finally
          KOLBitmap.Free;
        end;
      finally
        VCLBitmap.Free;
      end;
    end;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to convert this piece of logic with purely matrix operations instead
I would like to convert a yyyy-mm-dd to something like this: Saturday, 2 October
I would like to convert my BitmapImage to a System.Drawing.Image ? This is my
I would like to convert an Oracle SQL query into SQL server query. But
I would like to convert this /bin/sh syntax into a widely compatible Windows batch
I would like to convert an absolute path into a relative path. This is
I would like to convert this string {id:1,name:Test1},{id:2,name:Test2} to array of 2 JSON objects.
i would like convert xml, that: tag is the name of current node (this,
I would like to convert an IHTMLDOMNode to IHTMLElement in C#, I have tried
I would like to convert this SQL statement to a JPQL equivalent. SELECT *

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.