Tukata Posted January 19, 2010 Share Posted January 19, 2010 Hi I will appreciate if someone can write me the script for converting to grayscale and save to a file. Thank you tukata Link to comment Share on other sites More sharing options...
Yashied Posted January 19, 2010 Share Posted January 19, 2010 By using this library. My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More... Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 19, 2010 Moderators Share Posted January 19, 2010 Tukata,someone can write me the scriptHave you ever heard of the old saying: "Give a man a fish, you feed him for a day; give a man a net and you feed him forever"?Well, in this forum we try to be net makers and repairers, not fishmongers. Give it a try yourself first and come back if you run into problems. You know where we are! M23P.S. Did you even try "Search" - I did and there a loads of posts out there.  Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area  Link to comment Share on other sites More sharing options...
Mat Posted January 19, 2010 Share Posted January 19, 2010 Have you ever heard of the old saying: "Give a man a fish, you feed him for a day; give a man a net and you feed him forever"?Give a man a fire, and he'll be warm for a day. Set a man on fire and he'll be warm for the rest of his life. AutoIt Project Listing Link to comment Share on other sites More sharing options...
Tukata Posted January 19, 2010 Author Share Posted January 19, 2010 I tried to download FreeImage many times but the link takes me back. I searched the forum for almost one week. Can at least someone help me find FreeImage UDF ? tukata Link to comment Share on other sites More sharing options...
Mat Posted January 19, 2010 Share Posted January 19, 2010 follow the links http://progandy.co.cc/downloads?task=finish&cid=7&catid=3&m=0 AutoIt Project Listing Link to comment Share on other sites More sharing options...
picea892 Posted January 19, 2010 Share Posted January 19, 2010 LinkSee Malkey's post #7 Link to comment Share on other sites More sharing options...
Tukata Posted January 20, 2010 Author Share Posted January 20, 2010 I am tryig this script and can not find my mistake. #include <FreeImage.au3> _FreeImage_LoadDLL(@ScriptDir&"\FreeImage.dll") _FreeImage_Initialise() $sFile = @ScriptDir & "\flagirl.bmp" $FIF = _FreeImage_GetFIFFromFilenameU($sFile) $hImage = _FreeImage_LoadU($FIF, $sFile) _FreeImage_ConvertToGreyscale($hImage) $sFileName = @ScriptDir & "\New.bmp" _FreeImage_SaveU($FIF, $hImage, $sFileName) _FreeImage_Unload($hImage) _FreeImage_DeInitialise() Please help tukata Link to comment Share on other sites More sharing options...
Yashied Posted January 20, 2010 Share Posted January 20, 2010 #Include <FreeImage.au3> $sFile = 'Test.jpg' _FreeImage_LoadDLL(@ScriptDir & '\FreeImage.dll') _FreeImage_Initialise() $FIF = _FreeImage_GetFileTypeU($sFile) If $FIF = $FIF_UNKNOWN Then $FIF = _FreeImage_GetFIFFromFilenameU($sFile) EndIf $hImage = _FreeImage_LoadU($FIF, $sFile) $hGrey = _FreeImage_ConvertToGreyscale($hImage) _FreeImage_SaveU($FIF, $hGrey, @ScriptDir & '\Test_Grey.jpg') _FreeImage_Unload($hImage) _FreeImage_Unload($hGrey) _FreeImage_DeInitialise() My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More... Link to comment Share on other sites More sharing options...
Tukata Posted January 20, 2010 Author Share Posted January 20, 2010 Yashied, thank you very much ! I see that I have to include "FreeImage.dll" and "FreeImage.au3" which will increase the project by over 2200 kb. Is there any lighter way to do this ? Thank you tukata Link to comment Share on other sites More sharing options...
AndyG Posted January 20, 2010 Share Posted January 20, 2010 Hi, I found the following script in this forum somewhere ....expandcollapse popup#Include <GDIPlus.au3> _GDIPlus_Startup() $img = FileOpenDialog("Select an image", @ScriptDir & "\", "Images (*.jpg;*.bmp;*.png;*.gif)", 1) $hImage1 = _GDIPlus_ImageLoadFromFile($img) $hImage2 = _GDIPlus_ImageGreyscale($hImage1) $ext = StringMid($img, StringLen($img) -2) $sCLSID = _GDIPlus_EncodersGetCLSID ($ext) _GDIPlus_ImageSaveToFileEx($hImage2, StringMid($img, 1, StringLen($img) - 4) & "_grey." & $ext, $sCLSID) $iwx = _GDIPlus_ImageGetWidth($hImage2) $iwy = _GDIPlus_ImageGetHeight($hImage2) $hGUI = GUICreate("Convert image to greyscale by Siao", $iwx, $iwy) GUISetState() $hGraphic = _GDIPlus_GraphicsCreateFromHWND ($hGUI) _GDIPlus_GraphicsDrawImageRect($hGraphic, $hImage2, 0, 0, $iwx, $iwy) While GUIGetMsg() <> -3 * Sleep(50) WEnd _GDIPlus_ImageDispose($hImage1) _GDIPlus_ImageDispose($hImage2) _GDIPlus_ShutDown() Exit ;; _GDIPlus_ImageGreyscale() ;; Creates a greyscale copy of Image object and returns its handle. To destroy it, use _GDIPlus_ImageDispose() or _GDIPlus_BitmapDispose() Func _GDIPlus_ImageGreyscale(Const ByRef $hImage) Local $tColorMatrix, $x, $hImgAttrib, $iW = _GDIPlus_ImageGetWidth($hImage), $iH = _GDIPlus_ImageGetHeight($hImage), $hGraphics, $hGraphics2, $hBitmap ;;create color matrix data $tColorMatrix = DllStructCreate("float[5];float[5];float[5];float[5];float[5]") ;greyscale values: $x = DllStructSetData($tColorMatrix, 1, 0.30, 1) * DllStructSetData($tColorMatrix, 1, 0.30, 2) * DllStructSetData($tColorMatrix, 1, 0.30, 3) * _ DllStructSetData($tColorMatrix, 2, 0.59, 1) * DllStructSetData($tColorMatrix, 2, 0.59, 2) * DllStructSetData($tColorMatrix, 2, 0.59, 3) * _ DllStructSetData($tColorMatrix, 3, 0.11, 1) * DllStructSetData($tColorMatrix, 3, 0.11, 2) * DllStructSetData($tColorMatrix, 3, 0.11, 3) * _ DllStructSetData($tColorMatrix, 4, 1.00, 4) * DllStructSetData($tColorMatrix, 5, 1.00, 5) ;;create an image attributes object and update its color matrix $hImgAttrib = _GDIPlus_ImageAttributesCreate() _GDIPlus_ImageAttributesSetColorMatrix($hImgAttrib, 1, DllStructGetPtr($tColorMatrix)) ;;copy image $hGraphics = _GDIPlus_ImageGetGraphicsContext($hImage) $hBitmap = _GDIPlus_BitmapCreateFromGraphics($iW, $iH, $hGraphics) $hGraphics2 = _GDIPlus_ImageGetGraphicsContext($hBitmap) ;;draw original into copy with attributes _GDIPlus_GraphicsDrawImageRectRectEx($hGraphics2, $hImage, 0, 0, $iW, $iH, 0, 0, $iW, $iH, 2, $hImgAttrib) ;;clean up _GDIPlus_GraphicsDispose($hGraphics) _GDIPlus_GraphicsDispose($hGraphics2) _GDIPlus_ImageAttributesDispose($hImgAttrib) Return $hBitmap EndFunc ;;;;; other GDIPlus wrappers ;;;;; #cs _GDIPlus_ImageAttributesSetColorMatrix() Sets ColorMatrix of ImageAttributes object Parameters: $hImgAttrib = ImageAttributes object $iColorAdjustType = can be: ColorAdjustTypeDefault = 0 ColorAdjustTypeBitmap = 1 ColorAdjustTypeBrush = 2 ColorAdjustTypePen = 3 ColorAdjustTypeText = 4 ColorAdjustTypeCount = 5 ColorAdjustTypeAny (Reserved) = 6 $pColorMatrix = pointer to ColorMatrix structure $pGrayMatrix = pointer to GreyMatrix structure $iColorMatrixFlags = can be: ColorMatrixFlagsDefault = 0 ColorMatrixFlagsSkipGrays = 1 ColorMatrixFlagsAltGray = 2 Return value: True/False #ce Func _GDIPlus_ImageAttributesSetColorMatrix($hImgAttrib, $iColorAdjustType, $pColorMatrix = 0, $pGrayMatrix = 0, $iColorMatrixFlags = 0) Local $fEnable = 1, $aResult = DllCall($ghGDIPDll, "int", "GdipSetImageAttributesColorMatrix", "ptr",$hImgAttrib, "int",$iColorAdjustType, _ "int",$fEnable, "ptr",$pColorMatrix, "ptr",$pGrayMatrix, "int",$iColorMatrixFlags) Return SetError($aResult[0], 0, $aResult[0] = 0) EndFunc ;;Creates ImageAttributes object Func _GDIPlus_ImageAttributesCreate() Local $aResult = DllCall($ghGDIPDll, "int", "GdipCreateImageAttributes", "ptr*", 0) Return SetError($aResult[0], 0, $aResult[1]) EndFunc ;;Deletes ImageAttributes object Func _GDIPlus_ImageAttributesDispose($hImgAttrib) Local $aResult = DllCall($ghGDIPDll, "int", "GdipDisposeImageAttributes", "ptr", $hImgAttrib) Return SetError($aResult[0], 0, $aResult[0] = 0) EndFunc ;; _GDIPlus_GraphicsDrawImageRectRectEx() ;; Same as _GDIPlus_GraphicsDrawImageRectRect(), but adds 1 optional parameter - $hImgAttrib (handle to ImageAttributes object) Func _GDIPlus_GraphicsDrawImageRectRectEx($hGraphics, $hImage, $iSrcX, $iSrcY, $iSrcWidth, $iSrcHeight, $iDstX, $iDstY, $iDstWidth, $iDstHeight, $iUnit = 2, $hImgAttrib = 0) Local $aResult = DllCall($ghGDIPDll, "int", "GdipDrawImageRectRectI", "hwnd", $hGraphics, "hwnd", $hImage, "int", $iDstX, "int", _ $iDstY, "int", $iDstWidth, "int", $iDstHeight, "int", $iSrcX, "int", $iSrcY, "int", $iSrcWidth, "int", _ $iSrcHeight, "int", $iUnit, "ptr", $hImgAttrib, "int", 0, "int", 0) Return SetError($aResult[0], 0, $aResult[0] = 0) EndFunc Link to comment Share on other sites More sharing options...
Tukata Posted January 20, 2010 Author Share Posted January 20, 2010 WOW ! Thank you AndyG. That's what I was looking for and could not find. tukata Link to comment Share on other sites More sharing options...
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