Code: Select all
pToken := Gdip_Startup()
;-------------------------------------------------------------------------
; create the pBitmap
file := "C:\Users\ShareX\Screenshots\test.png"
DllCall("gdiplus\GdipCreateBitmapFromFile", "WStr", file, "PtrP", pBitmap)
DllCall("gdiplus\GdipGetImageWidth", "Ptr", pBitmap, "UIntP", w)
DllCall("gdiplus\GdipGetImageHeight", "Ptr", pBitmap, "UIntP", h)
;-------------------------------------------------------------------------
; create the hBitmap
hbm := CreateDIBSection(w, h)
mDC :=DllCall("CreateCompatibleDC", "Ptr",0, "Ptr")
oBM :=DllCall("SelectObject", "Ptr",mDC, "Ptr", hBM, "Ptr")
;-------------------------------------------------------------------------
; BitBlt the pBitmap to the hBitmap
pBitmapDC := DllCall("CreateCompatibleDC", "Ptr",0, "Ptr")
pBitmapOBM := DllCall("SelectObject", "Ptr",pDC, "Ptr", pBitmap, "Ptr")
DllCall("BitBlt","Ptr",mDC,"int", 0, "int", 0,"int",w,"int",h, "Ptr", pBitmapDC, "int",0, "int",0, "uint",0xCC0020)
DllCall("SelectObject", "Ptr", mDC, "Ptr", oBM)
DllCall("DeleteDC", "Ptr", mDC)
;-------------------------------------------------------------------------
; convert the hbitmap back to pBitmap just to save and check if it worked
DllCall("gdiplus\GdipCreateBitmapFromHBITMAP", "UPtr", hbm, "UPtr", 0, "UPtr*", newpBitmap)
outFile := "C:\Users\ShareX\Screenshots\test_2.png"
Gdip_SaveBitmapToFile(pBitmap, outFile) ; <- works, so it succeeded in creating the pBitmap
Gdip_SaveBitmapToFile(newpBitmap, outFile) ; <- fail the image is black
return
Code: Select all
CreateDIBSection(w, h, bpp:=32, ByRef ppvBits:=0, ByRef bi:="")
{
VarSetCapacity(bi, 40, 0), NumPut(40, bi, 0, "int")
, NumPut(w, bi, 4, "int"), NumPut(-h, bi, 8, "int")
, NumPut(1, bi, 12, "short"), NumPut(bpp, bi, 14, "short")
return DllCall("CreateDIBSection", "Ptr",0, "Ptr",&bi
, "int",0, "Ptr*",ppvBits:=0, "Ptr",0, "int",0, "Ptr")
}
when I save the `newpBitmap` the image is black, so it failed, what's going on?
the value of `newpBitmap` is not 0/null