nullschritt Posted August 4, 2013 Share Posted August 4, 2013 Hello forum, just wondering, if it's possible to resize an image with only GDI+? I need all images to be one size, but the origin image size is not always that size, so it would be optimal to be able to resize all images to a specific size, so the whole image is displayed on the whole control. Link to comment Share on other sites More sharing options...
UEZ Posted August 4, 2013 Share Posted August 4, 2013 (edited) Try this: _GDIPlus_ScaleImage2(). You can modify the function appropriately if you want to scale the bitmap directly instead of loading the bitmap first. Br,UEZ Edited August 4, 2013 by UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
Edano Posted August 4, 2013 Share Posted August 4, 2013 $ret=DllCall($ghGDIPDll,"int","GdipGetImageThumbnail","ptr",$hImage,"int",$Width,"int",$Height,"ptr*",0,"ptr",0,"ptr",0) $hImage=$ret[4] . with the handle, only one solution among others [color=rgb(255,0,0);][font="'comic sans ms', cursive;"]FukuLeaks[/color][/font] Link to comment Share on other sites More sharing options...
nullschritt Posted August 5, 2013 Author Share Posted August 5, 2013 $ret=DllCall($ghGDIPDll,"int","GdipGetImageThumbnail","ptr",$hImage,"int",$Width,"int",$Height,"ptr*",0,"ptr",0,"ptr",0) $hImage=$ret[4] . with the handle, only one solution among others So $hImage is the handle to the bitmap object? what is $ghGDIPDll? Link to comment Share on other sites More sharing options...
nullschritt Posted August 5, 2013 Author Share Posted August 5, 2013 Try this: _GDIPlus_ScaleImage2(). You can modify the function appropriately if you want to scale the bitmap directly instead of loading the bitmap first. Br, UEZ Thanks for your time, but I am looking for a solution to modify an already loaded bitmap(from memory), I think edano's solution might be what I was looking for. Link to comment Share on other sites More sharing options...
UEZ Posted August 5, 2013 Share Posted August 5, 2013 (edited) nullschritt,as mentioned you need to modify the function appropriately which is really easy to do. Func _GDIPlus_ScaleImage2($hImage, $iNewWidth, $iNewHeight, $iBGColor = 0xFFF0F0F0, $bBGClear = True, $iInterpolationMode = 7) ;coded by UEZ 2012 Local $iWidth = _GDIPlus_ImageGetWidth($hImage) Local $iHeight = _GDIPlus_ImageGetHeight($hImage) Local $iW, $iH, $f, $fRatio If $iWidth > $iHeight Then $f = $iWidth / $iNewWidth Else $f = $iHeight / $iNewHeight EndIf $iW = Int($iWidth / $f) $iH = Int($iHeight / $f) If $iW > $iNewWidth Then $fRatio = $iNewWidth / $iW $iW = Int($iW * $fRatio) $iH = Int($iH * $fRatio) ElseIf $iH > $iNewHeight Then $fRatio = $iNewHeight / $iH $iW = Int($iW * $fRatio) $iH = Int($iH * $fRatio) EndIf Local $hBitmap = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $iW, "int", $iH, "int", 0, "int", 0x0026200A, "ptr", 0, "int*", 0) If @error Then Return SetError(3, 0, 0) $hBitmap = $hBitmap[6] Local $hBmpCtxt = _GDIPlus_ImageGetGraphicsContext($hBitmap) If $bBGClear Then _GDIPlus_GraphicsClear($hBmpCtxt, $iBGColor) DllCall($ghGDIPDll, "uint", "GdipSetInterpolationMode", "handle", $hBmpCtxt, "int", $iInterpolationMode) _GDIPlus_GraphicsDrawImageRect($hBmpCtxt, $hImage, 0, 0, $iW, $iH) _GDIPlus_ImageDispose($hImage) _GDIPlus_GraphicsDispose($hBmpCtxt) Return $hBitmap EndFuncBr,UEZ Edited August 5, 2013 by UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
Edano Posted August 5, 2013 Share Posted August 5, 2013 (edited) in any case, $ghGDIPDll is the variable of the handle to gdiplus.dll that is globally assigned declared by calling _GDIPlusStartUp(). see _GDIPlus.au3 in the includes folder. Edited August 5, 2013 by Edano [color=rgb(255,0,0);][font="'comic sans ms', cursive;"]FukuLeaks[/color][/font] Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now