📄 createcompatiblebitmapu.pas
字号:
unit CreateCompatibleBitmapU;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Grids;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
{Note: This example works correctly only under a 256 color video driver}
procedure TForm1.Button1Click(Sender: TObject);
var
TheBitmap: HBitmap; // a handle for the new bitmap
TheBits: array[0..4095] of Byte; // an array of original bitmap bits
LoopX: Integer; // general loop counter variables
OffScreen: HDC; // an offscreen device context
ScreenDC: HDC; // a handle to a temporary device context
begin
{set every bit in the new bitmap to the color stored
in the system palette slot 3}
FillMemory(@TheBits, 4095, 3);
{set a 10 X 10 pixel square in the middle of the
image to the color in system palette slot 1}
for LoopX:=27 to 37 do
begin
TheBits[LoopX*64+27]:=1;
TheBits[LoopX*64+28]:=1;
TheBits[LoopX*64+29]:=1;
TheBits[LoopX*64+30]:=1;
TheBits[LoopX*64+31]:=1;
TheBits[LoopX*64+32]:=1;
TheBits[LoopX*64+33]:=1;
TheBits[LoopX*64+34]:=1;
TheBits[LoopX*64+35]:=1;
TheBits[LoopX*64+36]:=1;
end;
{retrieve a device context for the desktop}
ScreenDC := GetDC(0);
{create a 64 X 64 pixel bitmap that is
color compatible with the current display device}
TheBitmap := CreateCompatibleBitmap(ScreenDC, 64, 64);
{release the desktop device context}
ReleaseDC(0,ScreenDC);
{set the bitmap image}
SetBitmapBits(TheBitmap, 64*64, @TheBits);
{create an offscreen device context that is
compatible with the screen}
OffScreen := CreateCompatibleDC(0);
{select the new bitmap into the offscreen device context}
SelectObject(OffScreen, TheBitmap);
{copy the bitmap from the offscreen device context
onto the canvas of the form. this will display the bitmap}
BitBlt(Form1.Canvas.Handle,(Width div 2)-32,16,64,64,OffScreen,0,0,SRCCOPY);
{delete the offscreen device context}
DeleteDC(OffScreen);
{delete the new bitmap}
DeleteObject(TheBitmap);
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -