Sign in to follow this  
Followers 0
dirty

Center an image formula

4 posts in this topic

I know one here has to know how to calculate the image size based on

#1 Image dimensions

#2 Given frame to fin this image

#3 this code

#include <GDIPlus.au3>
    $PATH = GUICtrlRead ($MainImagePath)
    If Not @error Then
        _GDIPlus_Startup()
        $IMG = _GDIPlus_ImageLoadFromFile($PATH)
        $W = _GDIPlus_ImageGetWidth($IMG)
        $H = _GDIPlus_ImageGetHeight($IMG)
        _GDIPlus_ImageDispose($IMG)
        _GDIPlus_Shutdown()
        MsgBox(0,$PATH,$W & @CRLF & $H) ;size of an image

        $Image = GUICtrlCreatePic ("F:\Pictures\0106800001a.jpg",405,20,355,275) ;355X275 is area for an image
    EndIf

My image is 1280X960 by my Image area in GUI is smaller, so i want to resize this image to scale its self down till it fits keeping its size ration locked. 1 and most important thing to cincider is that there will be other images with different sizes, so is there a way to make this thing to calculate and scale an image regardless what size to fit into the given frame on my GUI ?

Thanks so much in advance.

Hope to get the formula soon :graduated: or something

Share this post


Link to post
Share on other sites



#Include <Math.au3>

$ImageWidth = 1280
$ImageHeight = 960
$AreaWidth = 355
$AreaHeight = 275

$Scale = _Min($AreaWidth / $ImageWidth, $AreaHeight / $ImageHeight)
$NewImageWidth = $ImageWidth * $Scale
$NewImageHeight = $ImageHeight * $Scale

ConsoleWrite(Round($NewImageWidth) & 'x' & Round($NewImageHeight) & @CR)

1 person likes this

Share this post


Link to post
Share on other sites

Look here:

Br,

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

Yashied thank you very much.

Was most simplified and easy to implement into existing code without having too much new variables.

Share this post


Link to post
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
Sign in to follow this  
Followers 0