Jump to content

FreeImage Library


ProgAndy
 Share

Recommended Posts

Posted Image

I am proud to announce an UDF collection for FreeImage.

The Library contains all functions of the 3.15.0.0-release (the documentaition is located here (PDF) )

If you need more informatin about the functions, you have to read the PDF since i did not include comments in the AU3-file.

If you want to download it, click here: [uDF] FreeImage library Downloads:Posted Image

And now an example for resizing an image (it saves the resized image in a new file, e.g. image.png will be saved as image_rsz.png)

#include <FreeImage.au3>

_FreeImage_LoadDLL(@ScriptDir&"\FreeImage.dll")
_FreeImage_Initialise()

$sFile = "800x600.jpg"
; new sizes
$width = 400
$height = 300

$FIF = _FreeImage_GetFileTypeU($sFile)
If $FIF = $FIF_UNKNOWN Then
    $FIF = _FreeImage_GetFIFFromFilenameU($sFile)
EndIf
$hImage = _FreeImage_LoadU($FIF, $sFile)

$hImageResized = _FreeImage_Rescale($hImage, $width, $height, $FILTER_LANCZOS3)
$dot = StringInStr($sFile,".",1,-1)
$Name = StringLeft($sFile,$dot-1)
$Ext = StringMid($sFile,$dot)
_FreeImage_SaveU($FIF, $hImageResized, $Name &"_rsz"&$Ext)
_FreeImage_Unload($hImage)
_FreeImage_Unload($hImageResized)

_FreeImage_DeInitialise()
</div>

And an other example for Flip and Rotate:

#include <FreeImage.au3>

Global $ImageHandle=-1, $WorkingFileName, $FIF

_FreeImage_LoadDLL(@ScriptDir&"\FreeImage.dll")
_FreeImage_Initialise()

Func OnAutoItExit()
    If $ImageHandle <>-1 Then _FreeImage_Unload($ImageHandle)
    _FreeImage_DeInitialise()
EndFunc

GUICreate("FreeImage Test GUI",800,700)
$ShowPic = GUICtrlCreatePic("",0,0, 800,600)

$btnOpen = GUICtrlCreateButton("Choose File", 10, 610, 100, 30)
GUICtrlSetTip(-1,"Only a copy of the image will be used")

$btnFlipH = GUICtrlCreateButton("Flip Horizontal", 120, 610, 100, 30)
$btnFlipV = GUICtrlCreateButton("Flip Vertical", 230, 610, 100, 30)
$btnRotate = GUICtrlCreateButton("Rotate ...", 340, 610, 100, 30)

GUISetState()

While 1
    Switch GUIGetMsg()
        Case -3
            Exit
        Case $btnOpen
            _OpenImage()
        Case $btnFlipH
            If $ImageHandle <> -1 Then
                _FreeImage_FlipHorizontal($ImageHandle)
                _FreeImage_SaveU($FIF, $ImageHandle, $WorkingFileName)
                _ShowImage()
            EndIf
        Case $btnFlipV
            If $ImageHandle <> -1 Then
                _FreeImage_FlipVertical($ImageHandle)
                _FreeImage_SaveU($FIF, $ImageHandle, $WorkingFileName)
                _ShowImage()
            EndIf
        Case $btnRotate
            If $ImageHandle <> -1 Then
                $hImageNew = _FreeImage_RotateClassic($ImageHandle, Number(InputBox("Rotate", "angle for rotation", 90)))
                _FreeImage_SaveU($FIF, $hImageNew, $WorkingFileName)
                _FreeImage_Unload($ImageHandle)
                $ImageHandle = $hImageNew
                _ShowImage()
            EndIf
    EndSwitch
WEnd

Func _OpenImage()
    Local $sFile = FileOpenDialog("Choose Image","", "Image Files (*.jpg;*.jpeg;*.bmp;*.gif)", 3)
    If @error Then Return
    If $ImageHandle <> -1 Then _FreeImage_Unload($ImageHandle)
    Local $dot = StringInStr($sFile,".",1,-1)
    Local $Name = StringLeft($sFile,$dot-1)
    Local $Ext = StringMid($sFile,$dot)
    $WorkingFileName = $Name &"_FI4AU3"&$Ext
    FileCopy($sFile,$WorkingFileName)
    $FIF = _FreeImage_GetFileTypeU($WorkingFileName)
    If $FIF = $FIF_UNKNOWN Then
        $FIF = _FreeImage_GetFIFFromFilenameU($WorkingFileName)
    EndIf
    $ImageHandle = _FreeImage_LoadU($FIF, $sFile)
    _ShowImage()
EndFunc

Func _ShowImage()
    Local $Width, $Height
    _SizeProportional($Width, $Height, 800, 600, _FreeImage_GetWidth($ImageHandle), _FreeImage_GetHeight($ImageHandle))
    GUICtrlSetPos($ShowPic,0,0,$Width, $Height)
    GUICtrlSetImage($ShowPic, $WorkingFileName)
EndFunc






Func _SizeProportional(ByRef $Width, ByRef $Height, $WDesired, $HDesired, $WSrc, $HSrc)
    ; Prog@ndy
    Local $RatioDes = ($WDesired / $HDesired)
    Local $CurrentRatio = ($WSrc / $HSrc)

    If $CurrentRatio > $RatioDes Then ; scale height
        $Width = $WDesired
        $Height = $WDesired / $CurrentRatio
    Else ; scale width
        $Width = $HDesired * $CurrentRatio
        $Height = $HDesired
    EndIf

EndFunc   ;==>_SizeProportional
Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

Corrected... forgot to rename it. That happens when you copy / paste functions 40 times in a row...

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

74 downloads and only one comment? Do you like it or not?

Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

I tried to download, the other day, for about dozen times and failed every time. :party:

edit: It's happening again. I just can't download. It starts and then DL slows down to 0 after few seconds. :)

Edited by trancexx

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

74 downloads and only one comment? Do you like it or not?

We all get this with lots of lookie-loos around here.

I used your demo and it worked fine. However, when I read some of the abilities of the dll, like rotations and etc, I thought maybe you should have given a better demo that displayed some of the capabilities of your UDF.

Nice job overall, just don't understand all the applications.

8)

NEWHeader1.png

Link to comment
Share on other sites

I tried to download, the other day, for about dozen times and failed every time. :)

I just downloaded it again and it worked fine.

1st click the download here ( above )

2nd click download at his site

3rd You have to check the checkbox that you agree to the terms of use....

4th click the download button at his site

5th... wait for it.... and whala!!! .... it'sdownloading

8)

Edited by Valuater

NEWHeader1.png

Link to comment
Share on other sites

I just downloaded it again and it worked fine.

1st click the download here ( above )

2nd click download at his site

3rd You have to check the checkbox that you agree to the terms of use....

4th click the download button at his site

5th... wait for it.... and whala!!! .... it'sdownloading

8)

Yes, I've gone thru elementary school.

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

I used your demo and it worked fine. However, when I read some of the abilities of the dll, like rotations and etc, I thought maybe you should have given a better demo that displayed some of the capabilities of your UDF.

Yeah, i didn't have time to write a good example. I'm thinking about a GUI with some Buttons :)

@trancexx: I'll send you a PN with the Library. I'm sorry, but i doN#t know the reason why it is not working for you.

Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

New example in first Post. Dont' forget to download the fixed UDFs :)

Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

  • Moderators

Nice work Progandy... certainly is a hog on the cpu during the calling sequences though.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Huge and nice work ProgAndy (as always :party: ).

...so, imagine the size of the heads of creators of FreeImage.dll. :)

One more thing. I see this thread is rated 3 and three peoples voted. Yashied gave 5. So, other two forum members rated it with 4 or 3 (together!!!). Either sick or by accident. In any case - stupid.

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

I believe that ProgAndy has done the hard work, and the result of the work exceeded all my expectations. This is definitely 5+. If someone does not understand how to use a library or do not want to understand, this is not the reason for the reduction of rating. This is not an objective opinion. This UDF will facilitate the work with images to many people. If you look at the counter, then the library has been downloaded 108 times during the 4 :) days. This speaks to the interest of people to this work. I do not understand what reasons people rated it at 3* or 4*. Maybe they will tell us about it?

Posted Image

Link to comment
Share on other sites

ProgAndy, 5 stars that I have promised.

Nice work Progandy... certainly is a hog on the cpu during the calling sequences though.

Good work man, was actually thinking of a similar UDF a couple of weeks ago but never got to it :)

Huge and nice work ProgAndy (as always :idea: ).

Thank you all :party:

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

  • 2 weeks later...

@ProgAndy

Nice work as usual.

If some feels better off with the COM version, you can download the wrapper here.

Including the Help file and Example application.

PhotoTrue 2.4 VB6 build

© 2000-2006 David Crowell

http://davidcrowell.com/phototrue

Royalty-free distribution

INTRODUCTION

PhotoTrue is an ActiveX DLL that allows manipulation of

true-color (continuous tone) images. PhotoTrue allows

reading and writing to JPG and BMP formats. PhotoTrue

is an inexpensive component, perfect for use in image

processing tools. PhotoTrue is also easy to deploy, and

is quite small.

Regards

ptrex

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