Creating a Simple BitMap
Create a BitMap by creating a "page" of screen memory and a page of memory and moving data back and forth.
procedure CopyBitMap(Form: TForm);
var
  Dc, MemDc, Image: THandle;
begin
  //Get a part of a window into a bitmap and place it in a new spot.

  //Set up Device Contexts
  Dc := GetDc(Form.Handle);
  MemDC := CreateCompatibleDC(DC);

  //Create bitmap to size of image (50x50)
  Image := CreateCompatibleBitmap(Dc, 50, 50);

  //Select the bitmap into memory
  Image := SelectObject(MemDC, Image);

  //Copy image from the Window (Form1) into the Bitmap.
  //Be certain there is something in there to copy.
  BitBlt(MemDC, 0, 0, 50, 50, DC, 0, 0, MergeCopy);

  //Display in new location
  BitBlt(DC, 216, 8, 197, 137, MemDC, 0, 0, MergeCopy);

  //Remove the BitMap from memory (Necessary?)
  Image := SelectObject(MemDC, Image);

  //Delete Bitmap
  DeleteObject(Image);

  //Remove Device Contexts
  DeleteDC(MemDC);
  ReleaseDC(Form.Handle, DC);
end;



Notes:
Be certain to delete unneeded Device Contexts (DC's and MemDc's) since these can eat your memory if misplaced.
Home