' load RGB png image from memory with FBImage ' ' Windows10 x64 22H2 + FreeBASIC 1.10.1 32bit + FBImage ' Last updated: <2024/02/03 18:47:11 +0900> ' リソースにアクセスするために windows.bi を使う #include "windows.bi" ' 画像読み込み用ライブラリ FBImage を使う #include once "FBImage.bi" ' カレントディレクトリを exeファイルのある場所にする chdir exepath() ' リソースにアクセスするための名前 Const res_name = "pngimage" Dim As HRSRC hResInfo Dim As HGLOBAL hResData Dim As ubyte Ptr resPtr Dim As DWORD resSize ' リソースを探す hResInfo = FindResource(NULL, strptr(res_name), RT_RCDATA) If hResInfo = Null Then Print "Error : Not found resource" : end End If ' リソースを読み込み hResData = LoadResource(0, hResInfo) If hResData = Null Then Print "Error : Not load resource" FreeResource(hResData) : end End If ' リソースのポインタを取得 resPtr = CPtr(ubyte Ptr, LockResource(hResData)) If resPtr = Null Then Print "Error : Not get resource pointer" FreeResource(hResData) : end End If ' リソースのサイズを取得 resSize = SizeofResource(NULL, hResInfo) If resSize = 0 Then Print "Error : Can not get resource size" FreeResource(hResData) : end End If ' デスクトップ解像度を指定 Dim As Integer scrw = 512 Dim As Integer scrh = 288 ' ウインドウサイズと色深度(bpp)を指定 screenres scrw, scrh, 32 ' メモリ上にある画像データを読み込む。ポインタとバイト数を渡す var img = LoadRGBAMemory(resPtr, resSize) ' リソースを解放 FreeResource(hResData) ' 画像を描画。RGB=(255, 0, 255) のピクセルは透明色として扱う Put (16, 16), img, TRANS ' キー入力があるまで待ち続ける sleep ' 画像を使い終わったので破棄 ImageDestroy img