timistar Posted July 7, 2010 Posted July 7, 2010 hi and thanks for read i see other post where the coder tray to load image file, crop or resize a and save a the new image, i tested diferent`s codes but i cant crop a part of a image what i need, can you please help give a help about how a can do this (no is the all code is the func or the link of the post ) all codes what i see the func crop a specific region of the image or used a print screen to crop, i try do wallapers from mi mobile phone, yea p is moore easy by photoshop , but dont moore funny ps i used this code to load, resize and ad the button crop and save dont dont work y mi newbie level (let you the original ocde, with out mi posible errors) thx many http://www.autoitscript.com/forum/index.php?showtopic=95357&st=0&p=685512&hl=flip&fromsearch=1&#entry685512 expandcollapse popup#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 thx
ProgAndy Posted July 8, 2010 Posted July 8, 2010 _FreeImage_Copy allows to create a cropped copy of an image. expandcollapse popup#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) $btnInvert = GUICtrlCreateButton("Invert", 450, 610, 100, 30) $btnCrop = GUICtrlCreateButton("Crop ...", 560, 610, 100, 30) $inpCropX = GUICtrlCreateInput("", 560, 650, 50, 20) GUICtrlSetTip(-1, "Crop X-Position") $inpCropY = GUICtrlCreateInput("", 610, 650, 50, 20) GUICtrlSetTip(-1, "Crop Y-Position") $inpCropW = GUICtrlCreateInput("", 560, 670, 50, 20) GUICtrlSetTip(-1, "Crop Width") $inpCropH = GUICtrlCreateInput("", 610, 670, 50, 20) GUICtrlSetTip(-1, "Crop Height") 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 $btnInvert If $ImageHandle <> -1 Then MsgBox( 0, "", _FreeImage_Invert($ImageHandle) & " - " & @error) _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 Case $btnCrop Local $x = Int(GUICtrlRead($inpCropX)), $y = Int(GUICtrlRead($inpCropY)), $w = Int(GUICtrlRead($inpCropW)), $h = Int(GUICtrlRead($inpCropH)) If $x>=0 And $y>=0 And $w>0 And $h>0 Then $hImageNew = _FreeImage_Copy($ImageHandle, $x, $y, $x+$w, $y+$h) _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;*.png)", 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) If $Ext = ".png" Then $WorkingFileName = $Name &"_FI4AU3"&".jpg" $FIF = $FIF_PNG $ImageHandle = _FreeImage_LoadU($FIF, $sFile) $ImageHandle2 = _FreeImage_ConvertTo24Bits($ImageHandle) _FreeImage_Unload($ImageHandle) $FIF = $FIF_JPEG _FreeImage_SaveU($FIF, $ImageHandle2, $WorkingFileName) _FreeImage_Unload($ImageHandle2) Else $WorkingFileName = $Name &"_FI4AU3"&$Ext FileCopy($sFile,$WorkingFileName) EndIf $FIF = _FreeImage_GetFileTypeU($WorkingFileName) If $FIF = $FIF_UNKNOWN Then $FIF = _FreeImage_GetFIFFromFilenameU($WorkingFileName) EndIf $ImageHandle = _FreeImage_LoadU($FIF, $WorkingFileName) _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 *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
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