|
Reduce a Bitmap |
procedure ReduceBitMap(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 Image := CreateCompatibleBitmap(Dc, 500, 400); //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...place a //TImage located at 0,0 and load a file there) BitBlt(MemDC, 0, 0, 280, 380, DC, 0, 0, MergeCopy); //Display in new location StretchBlt(DC, 300, 70, 100, 200, MemDC, 0, 0, 200, 400, MergeCopy); //Remove the BitMap from memory 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. |