LoadPicture

ファイルから画像を読み込み、ビットマップまたはアイコンハンドルを返します。

Handle := LoadPicture(Filename , Options, &OutImageType)

パラメータ

Filename

型:文字列

画像のファイル名。絶対パスが指定されていない場合、通常はA_WorkingDirにあると仮定されます。DLLまたはEXEファイルの名前がパスなしで与えられた場合、現在の実行ファイル(AutoHotkey.exeまたはコンパイルされたスクリプト)のディレクトリまたはシステムディレクトリからロードされる場合があります。

Options

型:文字列

If blank or omitted, it defaults to no options. Otherwise, specify a string of one or more of the following options, each separated from the next with a space or tab:

Wn および Hn:画像を読み込む幅と高さを指定します。nは整数です。一方の寸法が省略または-1された場合、もう一方の寸法をもとに縦横比を保ったまま自動計算されます。両方が省略された場合、画像のオリジナルサイズが使用されます。どちらかの寸法が0であれば、その寸法に対してオリジナルサイズが使用されます。事例:"w80 h50""w48 h-1"または"w48"(縦横比を維持)、"h0 w100"(元の高さを使用し、幅をオーバーライド)。

Iconn:複数のアイコンを持つファイル(一般にEXEファイルやDLLファイル)から、どのアイコンを読み込むかを示します。例えば、"Icon2 "は、ファイルの2番目のアイコンをロードします。"Icon1"を指定することで、対応している画像フォーマットであれば、どのようなものでもアイコンに変換することが可能です。However, the icon is converted back to a bitmap if the OutImageType parameter is omitted.

GDI+: Use GDI+ to load the image, if available. 例えば、"GDI+ w100".

&OutImageType

型:VarRef

If omitted, the corresponding value will not be stored, and the return value will always be a bitmap handle (icons/cursors are converted if necessary) because reliably using or deleting an icon/cursor/bitmap handle requires knowing which type it is. Otherwise, specify a reference to the output variable in which to store a number indicating the type of handle being returned: 0 (IMAGE_BITMAP), 1 (IMAGE_ICON) or 2 (IMAGE_CURSOR).

戻り値

型:整数

This function returns a bitmap or icon handle depending on whether a picture or icon is specified and whether the &OutImageType parameter is present or not.

備考

LoadPicture also supports the handle syntax, such as for creating a resized image based on an icon or bitmap which has already been loaded into memory, or converting an icon to a bitmap by omitting &OutImageType.

画像をメモリから解放する必要がある場合は、ハンドルの種類に応じて適切な関数を呼び出します。

if (not OutImageType)  ; IMAGE_BITMAP (0) or the OutImageType parameter was omitted.
    DllCall("DeleteObject", "ptr", Handle)
else if (OutImageType = 1)  ; IMAGE_ICON
    DllCall("DestroyIcon", "ptr", Handle)
else if (OutImageType = 2)  ; IMAGE_CURSOR
    DllCall("DestroyCursor", "ptr", Handle)

イメージハンドル

一部の画像をプリロードして再利用します。

Pics := []
; 展示する写真を探す。
Loop Files, A_WinDir "\Web\Wallpaper\*.jpg", "R"
{
    ; 各画像を読み込み、配列に追加する。
    Pics.Push(LoadPicture(A_LoopFileFullPath))
}
if !Pics.Length
{
    ; このような場合は、上記のLoop行のパスを編集してください。
    MsgBox("No pictures found!Try a different directory.")
    ExitApp
}
; ピクチャーコントロールを追加し、1枚目のピクチャーのアスペクト比を保持します。
MyGui := Gui()
Pic := MyGui.Add("Pic", "w600 h-1 +Border", "HBITMAP:*" Pics[1])
MyGui.OnEvent("Escape", (*) => ExitApp())
MyGui.OnEvent("Close", (*) => ExitApp())
MyGui.Show
Loop
{
    ; 写真を切り替えます!
    Pic.Value := "HBITMAP:*" Pics[Mod(A_Index, Pics.Length)+1]
    Sleep 3000
}