GDI_CreateBitmapFromFile(dir,w=0,h=0,bkg=0) {
bOut:=Gdip_CreateBitmap(w,h)
graphics:=Gdip_GraphicsFromImage(bOut)
start:=A_TickCount
;Gdip_SetInterpolationMode(graphics,5)
;Gdip_BitmapSetResolution()
H:=File_Open("Read",dir)
size:=File_Read(H,data,File_Size(H))
hData := DllCall("GlobalAlloc", "UInt",2, "UInt",size)
pData := DllCall("GlobalLock", "UInt",hData, "Ptr")
DllCall("RtlMoveMemory", "Ptr",pData, "Ptr",&data, "UInt",size)
DllCall("GlobalUnlock", "UInt",hData)
rc3 := DllCall("ole32\CreateStreamOnHGlobal", "UInt",hData, "Int",True, "Ptr*",pStream)
DllCall("gdiplus\GdipCreateBitmapFromStream", "UPtr", pStream, "UPtr*", pBitmap, "UInt") "`nh=" H
;DllCall("gdiplus\GdipImageForceValidation", Ptr, pBitmap)
;Gdip_SetInterpolationMode(graphics,1)
;Gdip_SetSmoothingMode(graphics,3)
Gdip_DrawImage(graphics,pBitmap, 0,0,w,h,0,0,Gdip_GetImageWidth(pBitmap),Gdip_GetImageHeight(pBitmap),1)
msgbox % A_TickCount-start "ms"
Gdip_DeleteGraphics(graphics)
Gdip_DisposeImage(bitmap)
return bOut
}
File_Open(sType, sFile) {
bRead := InStr(sType, "READ")
bSeq := sType = "READSEQ"
;Open the file for writing with GENERIC_WRITE/GENERIC_READ, NO SHARING/FILE_SHARE_READ & FILE_SHARE_WRITE, and
;OPEN_ALWAYS/OPEN_EXISTING, and FILE_FLAG_SEQUENTIAL_SCAN
hFile := DllCall("CreateFile", "Str", sFile, "UInt", bRead ? 0x80000000 : 0x40000000, "UInt", bRead ? 3 : 0, "Ptr", 0
, "UInt", bRead ? 3 : 4, "UInt", bSeq ? 0x08000000 : 0, "Ptr", 0, "Ptr")
If (hFile=-1 || ErrorLevel) { ;Check for any error other than ERROR_FILE_EXISTS
ErrorLevel := ErrorLevel ? ErrorLevel : A_LastError
Return 0 ;Return INVALID_HANDLE_VALUE
} Else Return hFile
}
File_Read(hFile, ByRef bData, iLength = 0, bPtr=0) {
;Check if we're reading up to the rest of the file
If Not iLength ;Set the length equal to the remaining part of the file
iLength := File_Size(hFile) - File_Pointer(hFile)
;Prep the variable
if(!bPtr)
VarSetCapacity(bData, iLength, 0)
;Read the file
r := DllCall("ReadFile", "Ptr", hFile, "Ptr", (bPtr?bData:&bData), "UInt", iLength, "UInt*", iLengthRead, "Ptr", 0)
If (Not r Or ErrorLevel) {
ErrorLevel := ErrorLevel ? ErrorLevel : A_LastError
Return 0
} Else Return iLengthRead
}
File_Size(hFile) {
r := DllCall("GetFileSizeEx", "Ptr", hFile, "Int64*", iFileSize)
If (Not r Or ErrorLevel) {
ErrorLevel := ErrorLevel ? ErrorLevel : A_LastError
Return 0
} Else Return iFileSize
}