Jump to content

Resizing an image (with GDI+)


Recommended Posts

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

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 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

$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

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
EndFunc
Br,

UEZ

Edited 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

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 by Edano

[color=rgb(255,0,0);][font="'comic sans ms', cursive;"]FukuLeaks[/color][/font]

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...