调整图像功能不会保存任何内容

时间:2016-10-23 01:01:56

标签: autohotkey

尝试调整图像大小,但我发现的以下功能不会产生任何结果。我认为该函数需要将位图保存到文件,所以我添加了该代码..但没有保存。所有ahk文件和图像都在同一个文件夹中。

#Include Gdip.ahk

If !pToken := Gdip_Startup()
{
    MsgBox, 48, gdiplus error!, Gdiplus failed to start. Please ensure you have gdiplus on your system
    ExitApp
}
pBitmap := "test.bmp"
pResizedBitmap := Gdip_ResizeBitmap(pBitmap, 200, 0)
Gdip_SaveBitmapToFile(pResizedBitmap, "Resize.png")
Gdip_Shutdown(pToken)
MsgBox

Gdip_ResizeBitmap(pBitmap, PercentOrWH, Dispose=1) {    ; returns resized bitmap. By Learning one.
    Gdip_GetImageDimensions(pBitmap, origW, origH)
    if PercentOrWH contains w,h
    {
        RegExMatch(PercentOrWH, "i)w(\d*)", w), RegExMatch(PercentOrWH, "i)h(\d*)", h)
        NewWidth := w1, NewHeight := h1
        NewWidth := (NewWidth = "") ? origW/(origH/NewHeight) : NewWidth
        NewHeight := (NewHeight = "") ? origH/(origW/NewWidth) : NewHeight
    }
    else
    NewWidth := origW*PercentOrWH/100, NewHeight := origH*PercentOrWH/100       
    pBitmap2 := Gdip_CreateBitmap(NewWidth, NewHeight)
    G2 := Gdip_GraphicsFromImage(pBitmap2), Gdip_SetSmoothingMode(G2, 4), Gdip_SetInterpolationMode(G2, 7)
    Gdip_DrawImage(G2, pBitmap, 0, 0, NewWidth, NewHeight)
    Gdip_DeleteGraphics(G2)
    if Dispose
        Gdip_DisposeImage(pBitmap)
    return pBitmap2
}

非常感谢任何帮助!

1 个答案:

答案 0 :(得分:0)

pBitmap := "test.bmp"

不行。您必须从Gdip库调用Gdip_CreateBitmapFromFile()函数来创建指向位图的指针。在example 6中,您可以看到它被使用。

就像那样(其余的应该有效):

pBitmap := Gdip_CreateBitmapFromFile("test.bmp")