调整图像大小功能不保存任何内容
Resize image function doesn't save anything
正在尝试调整图像大小,但我发现的以下函数没有产生任何结果。我认为该函数需要将位图保存到文件中,所以我添加了该代码……但没有保存任何内容。所有 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
}
如有任何帮助,我们将不胜感激!
pBitmap := "test.bmp"
行不通。您必须调用 Gdip 库中的 Gdip_CreateBitmapFromFile()
函数来创建指向位图的指针。在 example 6 你可以看到它正在被使用。
像那样(其余的应该工作):
pBitmap := Gdip_CreateBitmapFromFile("test.bmp")
正在尝试调整图像大小,但我发现的以下函数没有产生任何结果。我认为该函数需要将位图保存到文件中,所以我添加了该代码……但没有保存任何内容。所有 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
}
如有任何帮助,我们将不胜感激!
pBitmap := "test.bmp"
行不通。您必须调用 Gdip 库中的 Gdip_CreateBitmapFromFile()
函数来创建指向位图的指针。在 example 6 你可以看到它正在被使用。
像那样(其余的应该工作):
pBitmap := Gdip_CreateBitmapFromFile("test.bmp")