You could try this, seems like it ought to work, though I know nothing of GameMaker's image layers. This creates a 32bit transparent image that should serve. An alternative would be to use PB's EncodeImage command to create a PNG or JPG if GM has the decoder for that.
Code: Select all
Procedure SaveImage2Memory(hBmp)
GetObject_(hBmp, SizeOf(BITMAP), @Bmp.BITMAP)
With bmiInfo.BITMAPINFOHEADER
\biSize = SizeOf(BITMAPINFOHEADER)
\biWidth = bmp\bmWidth
\biHeight = bmp\bmHeight
\biPlanes = 1
\biBitCount = 32
\biCompression = #BI_RGB
EndWith
*pPixels = AllocateMemory(bmp\bmWidthBytes*bmp\bmHeight)
hDC = GetWindowDC_(#Null)
iRes = GetDIBits_(hDC, hBmp, 0, bmp\bmHeight, *pPixels, @bmiInfo, #DIB_RGB_COLORS)
ReleaseDC_(#Null, hDC)
ImageSize = SizeOf(BITMAPFILEHEADER) + SizeOf(BITMAPINFOHEADER) + MemorySize(*pPixels)
*rawimage = AllocateMemory(ImageSize)
*fileheader.BITMAPFILEHEADER = *rawimage
*header.BITMAPINFOHEADER = *rawimage + SizeOf(BITMAPFILEHEADER)
With *fileheader
\bfType = 19778 ; word containing 2 bytes, 'BM' for 'BIT' 'MAP' ;)
\bfSize = ImageSize
\bfOffBits = SizeOf(BITMAPFILEHEADER) + SizeOf(BITMAPINFOHEADER)
EndWith
CopyMemory(@BmiInfo, *header, SizeOf(BITMAPINFOHEADER))
CopyMemory(*pPixels, *rawimage + SizeOf(BITMAPFILEHEADER) + SizeOf(BITMAPINFOHEADER), MemorySize(*pPixels))
FreeMemory(*pPixels)
ProcedureReturn *rawimage
EndProcedure
ProcedureDLL CreateBlankImage(szw, szh)
hImage = CreateImage(#PB_Any, szw, szh, 32|#PB_Image_Transparent)
If hImage
*this = SaveImage2Memory(ImageID(hImage))
FreeImage(hImage)
ProcedureReturn *this
Else
ProcedureReturn 0
EndIf
EndProcedure
ProcedureDLL FreeBlankImage(*address)
If FreeMemory(*address)
ProcedureReturn 1
Else
ProcedureReturn 0
EndIf
EndProcedure
One thing to watch for in this code is that you will probably cause a crash if you try to free the same image address twice. The first time will succeed but there is no IsMemory function to test if the memory is valid so a subsequent call with the same address might crash. I didn't test it but it seems likely.