📄 loadbitmapu.pas
字号:
unit LoadBitmapU;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls, StdCtrls;
type
TForm1 = class(TForm)
ComboBox1: TComboBox;
Panel1: TPanel;
Panel2: TPanel;
Image1: TImage;
Image2: TImage;
Label1: TLabel;
Label2: TLabel;
procedure ComboBox1Change(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.ComboBox1Change(Sender: TObject);
var
TheBitmap: HBITMAP; // holds the bitmap
BitmapInfo: Windows.TBitmap; // holds the bitmap information
OffscreenDC: HDC; // a handle to an offscreen device context
{this defines all of the system bitmaps available in Windows}
type
TBitmapTypes = array[0..25] of Integer;
const
BitmapTypes: TBitmapTypes = (OBM_CLOSE,OBM_UPARROW,OBM_DNARROW,OBM_RGARROW,
OBM_LFARROW,OBM_REDUCE,OBM_ZOOM,OBM_RESTORE,
OBM_REDUCED,OBM_ZOOMD,OBM_RESTORED,OBM_UPARROWD,
OBM_DNARROWD,OBM_RGARROWD,OBM_LFARROWD,
OBM_MNARROW,OBM_COMBO,OBM_UPARROWI,OBM_DNARROWI,
OBM_RGARROWI,OBM_LFARROWI,OBM_BTSIZE,
OBM_CHECK,OBM_CHECKBOXES,OBM_BTNCORNERS,
OBM_SIZE);
begin
{erase the last images}
Image1.Canvas.Brush.Color:=clBtnFace;
Image2.Canvas.Brush.Color:=clBtnFace;
Image1.Canvas.Fillrect(Image1.Canvas.Cliprect);
Image2.Canvas.Fillrect(Image2.Canvas.Cliprect);
{load the selected bitmap}
TheBitmap:=LoadBitmap(0, MakeIntResource(BitmapTypes[ComboBox1.ItemIndex]));
{create an offscreen device context and select the bitmap into it}
OffscreenDC:=CreateCompatibleDC(0);
SelectObject(OffscreenDC, TheBitmap);
{fill in a BITMAP information structure}
GetObject(TheBitmap, SizeOf(Windows.TBitmap), @BitmapInfo);
{draw the bitmap into Image1}
BitBlt(Image1.Canvas.Handle, 45,45,Image1.Width, Image1.Height,OffscreenDC,
0,0,SRCCOPY);
{verify the stretch mode in Image2 is what we want}
if GetStretchBltMode(Image2.Canvas.Handle)<>COLORONCOLOR then
SetStretchBltMode(Image2.Canvas.Handle, COLORONCOLOR);
{draw the bitmap into Image2, stretching it to fill the image}
StretchBlt(Image2.Canvas.Handle, 0, 0, Image2.Width, Image2.Height,
OffscreenDC, 0, 0, BitmapInfo.bmWidth, BitmapInfo.bmHeight, SRCCOPY);
{delete the bitmap}
DeleteObject(TheBitmap);
{delete the offscreen device context}
DeleteDC(OffscreenDC);
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -