Jump to content

Recommended Posts

Posted

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

Posted

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

Posted

Yashied thank you very much.

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

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
  • Recently Browsing   0 members

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