Will66 Posted January 25, 2007 Share Posted January 25, 2007 (edited) I've been playing around with cxImgeAlt.dll and thought others might get some use from it.The example script basically resamples a selected image from the file open menu and saves it to the script directory then displays it.The dll needs to be registered to use it, if you take a look at the dll's methods with ole.exe viewer you will see there are many image functions like rotate, greyscale, flip, mirror, etc etcAsp examples: http://www.google.com.au/search?hl=en&...earch&meta=CxImageATL.dllCxImageATL.au3CxImageALT.au3expandcollapse popup#include <GUIConstants.au3> $Form1 = GUICreate("CxImage", 633, 454, 193, 115,$WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPCHILDREN ) Dim $filemenu = GUICtrlCreateMenu ("&File") Dim $fileitem = GUICtrlCreateMenuitem ("Open",$filemenu) Dim $widthTh,$heightTh $Height1=150 $Width1=150 $Obj1_ctrl = GUICtrlCreatePic("",120, 32,$Width1,$Height1) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $fileitem ;MsgBox(0,"","msg") $file = FileOpenDialog("Choose file...",@ScriptDir,"Picture Files (*.*)") If @error <> 1 Then pic_Open($file) EndSwitch WEnd Func pic_Open($file) GUICtrlDelete($Obj1_ctrl) $newFile = resample($file,$Width1,$Height1) $Obj1_ctrl = GUICtrlCreatePic(@ScriptDir & "\cximage5.jpg",120, 32,$widthTh,$heightTh) ;MsgBox(0,"",$file) EndFunc Func resample($file,$Width1,$Height) $objCxImage = ObjCreate("CxImageATL.CxImage") ;$objCxImage.Destroy() $objCxImage.Load($file,2) ;$objCxImage.RotateLeft() $objCxImage.IncreaseBpp(24) $widthOrig = $objCxImage.GetWidth() $heightOrig = $objCxImage.GetHeight() ;MsgBox(0,"",$widthOrig & "x" & $heightOrig) $fx = $widthOrig/$Width1 $fy = $heightOrig/$Height1;subsample factors ;MsgBox(0,"",$fx & "x" & $fy) ; must fit in thumbnail size If $fx>$fy Then $f=$fx Else $f=$fy; Max(fx,fy) EndIf $widthTh = Int($widthOrig/$f) $heightTh = Int($heightOrig/$f) $objCxImage.Resample($widthTh,$heightTh,2) $objCxImage.SetJpegQuality(100) $objCxImage.Save(@ScriptDir & "\cximage5.jpg", 2) $objCxImage.Destroy() EndFunc Edited January 25, 2007 by Will66 Link to comment Share on other sites More sharing options...
nobbe Posted January 25, 2007 Share Posted January 25, 2007 hi this is very nice! i was trying to do the same for imagemagick library, but i guess i switch to cximage now :-) i will try to figure out the methods now.. PS : for those who dont know how to register the dll copy CxImageATL.dll c:\winnt\system32 regsvr32.exe CxImageATL.dll Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted January 25, 2007 Moderators Share Posted January 25, 2007 Echo? 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 More sharing options...
Will66 Posted January 25, 2007 Author Share Posted January 25, 2007 oleview.exe you can check the methods. I don't know how to call the dll directly eg dlcall(), maybe someone more knowedgable can take a look. I was using infranview for a while but even that has licence limitations regarding distibution. This is half the size and the registration process can be scripted. I've been saving the image to file before displaying it but there is a few methods to display an image directly out of memmory i believe, eg ImageForASP(), copyToHandle()...etc but i can't figure out how to do that with autoit......again somene more knowledgable may know this. Link to comment Share on other sites More sharing options...
trids Posted January 25, 2007 Share Posted January 25, 2007 Very nice - tx! Link to comment Share on other sites More sharing options...
Will66 Posted February 3, 2007 Author Share Posted February 3, 2007 Screen Shot example: expandcollapse popupConst $CF_BITMAP = 2 $Height1=400 $Width1=400 ;open clipboard DLLCall("user32.dll","int", "OpenClipboard","hwnd",0) $bbmp = DllCall("user32.dll", "int", "GetClipboardData", "int", $CF_BITMAP) $bbmp0 = $bbmp[0] $bbmp1 = $bbmp[1] ;close clipboard DLLCall("user32.dll","int","CloseClipboard") $objCxImage = ObjCreate("CxImageATL.CxImage") $objCxImage.CreateFromHANDLE($bbmp1) $objCxImage.CreateFromHBITMAP($bbmp0) #cs $objCxImage.IncreaseBpp(24) $widthOrig = $objCxImage.GetWidth() $heightOrig = $objCxImage.GetHeight() ;MsgBox(0,"",$widthOrig & "x" & $heightOrig) $fx = $widthOrig/$Width1 $fy = $heightOrig/$Height1 ;subsample factors If $fx>$fy Then $f=$fx Else $f=$fy ; Max(fx,fy) EndIf $widthTh = Int($widthOrig/$f) $heightTh = Int($heightOrig/$f) $objCxImage.SetJpegQuality(95) $objCxImage.Resample($widthTh,$heightTh,2) ;$objCxImage.Mirror(); #ce $objCxImage.Save(@ScriptDir & "\cximage5.bmp", 0) ;0=bmp,1=gif,2=jpg,3=png,4=ico,5=tif,6=tga,7=pcx $objCxImage.Destroy() Link to comment Share on other sites More sharing options...
SmiLe Posted February 4, 2007 Share Posted February 4, 2007 Another nice example script, thank you Will66! After reading again the documentation, I think cxImageATL.dll is definetly a better choice than GDLibrary.dll. Except I didn't manage to call cxImage.DrawString nor cxImage.DrawStringEx. Any idea? Link to comment Share on other sites More sharing options...
Will66 Posted February 4, 2007 Author Share Posted February 4, 2007 (edited) Don't be confused, i've been using auto <1 month and dll's even less.My background is asp/vbscript/javascript......calling dll's and deciphering C language methods is something new and uncomfortable.I'm guessing you used the Create method first? I'll check it out and see if i can...this ones interesting with a nice vbs example in the download http://www.lutanho.net/diagram/index.html?download.htmlEdit: btw in an above post it shows png as type 3, I believe it is actually type 0 Edited February 4, 2007 by Will66 Link to comment Share on other sites More sharing options...
Will66 Posted February 4, 2007 Author Share Posted February 4, 2007 Using gdImage.dll creates a png configured from script: $Img=ObjCreate("gdImage.Images.1") $i=$Img.ImageCreate(80, 40) ;returns 0, index of first unused ImageIndex in ImagePointerArray $Img.ImageColorAllocate( $i,106,194,46 );ImageIndex, RedBG, GreenBG, BlueBG, $c=$Img.ImageColorAllocate($i,170,0,72) ;returns ColorIndex $Img.ImageRectangle ($i, 10, 10, 70, 30, $c) $c=$Img.ImageColorAllocate($i,200,0,255) ;returns ColorIndex $Img.ImageString ($i, 4, 20, 12, "test", $c) ;'ImageIndex, FontStyle (1..5), x, y, string, color $FN=@ScriptDir & "\test22.png" ;if isObject(Server) then FN=Server.mappath(FN) $Img.ImagePng ($i, $FN) $Img.ImageDestroy ($i) ;$Img="" Link to comment Share on other sites More sharing options...
SmiLe Posted February 4, 2007 Share Posted February 4, 2007 (edited) Well, to explain more precisely the problem, I was trying to draw a text string on an existing Jpeg image. According to the documentation, the cxImage function is DrawString:long CxImage::DrawString (HDC hdc, long x, long y, const TCHAR *text, RGBQUAD color, const TCHAR *font, long lSize=0, long lWeight=400, BYTE bItalic=0, BYTE bUnderline=0, bool bSetAlpha=false)So I think the AutoIt script should be something like this:CODE$oCxImage = ObjCreate("CxImageATL.CxImage")If IsObj($oCxImage) Then $oCxImage.Load("C:\mypic.jpg", 2) $oCxImage.IncreaseBpp(24) $oCxImage.DrawString(10, 10, "Hello World!", $Color, "Arial", 24, 400, 0, 0, False) ; <--- ??? $oCxImage.SetJpegQuality(80) $oCxImage.Save("C:\mynewpic.jpg", 2) $oCxImage.Destroy()EndIfBut I don't know what $Color is supposed to be (what is RGBQUAD type?). And perhaps there is something else wrong. Edited February 4, 2007 by SmiLe Link to comment Share on other sites More sharing options...
Will66 Posted February 4, 2007 Author Share Posted February 4, 2007 RGB color code? $Color=055131 you've ommited hdc argument? where did you get the documentation. oleview.exe does'nt reaveal drawstring method Link to comment Share on other sites More sharing options...
SmiLe Posted February 4, 2007 Share Posted February 4, 2007 (edited) The documentation is there : http://www.xdp.it/cximage/ (DrawString is in "Modules" -> "Painting").I have seen somewhere this code snippet:RGBQUAD color = { 0, 0, 0, 0 }; xImg.DrawString(NULL, 0, 0, "Hello", color, "Tahoma", 30); Edited February 4, 2007 by SmiLe Link to comment Share on other sites More sharing options...
Will66 Posted February 4, 2007 Author Share Posted February 4, 2007 Those methods are for CxImage, not CxImageALT which is wrapper for asp. Link to comment Share on other sites More sharing options...
SmiLe Posted February 4, 2007 Share Posted February 4, 2007 I thought the same methods were available throught the wrapper... Now I understand there is no way to do what I wanted with CxImageATL! Link to comment Share on other sites More sharing options...
magician13134 Posted February 16, 2007 Share Posted February 16, 2007 I'm having trouble getting any of this working :"> I copied the screenshot example to a folder with the other au3 and the dll in this thread and got this error: G:\AU3 Image\ss.au3 (17) : ==> Variable must be of type "Object".: $objCxImage.CreateFromHANDLE($bbmp1) $objCxImage^ ERROR Any help? Thanks Visit Magic Soft Inc. for some of my software Link to comment Share on other sites More sharing options...
Will66 Posted February 17, 2007 Author Share Posted February 17, 2007 (edited) It looks like you have registered the dll? do a printscreen before running the script:alt or ctrl prtSc?? Edited February 17, 2007 by Will66 Link to comment Share on other sites More sharing options...
MrCreatoR Posted March 25, 2007 Share Posted March 25, 2007 Thanks Will66 - This is what i have looked for! Maybe it is possible to make this dll litle bit smaller? i need from it just to save captured image to file.  Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1  AutoIt Russian Community My Work... Spoiler Projects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ==================================================    AutoIt is simple, subtle, elegant. © AutoIt Team Link to comment Share on other sites More sharing options...
luvmachine Posted April 8, 2007 Share Posted April 8, 2007 Anybody have a clue if you can get CxImageATL.dll to work with other image types? When I tried various numbers for the image type with Load() I only seem to be able to get jpg's to be able to be loaded and saved. While when I did some reading online it seems the original C library could load any image type, as long as you named the right type, and resave it as another image type. However I couldn't find any other downloads of the CxImageATL.dll Link to comment Share on other sites More sharing options...
Will66 Posted April 9, 2007 Author Share Posted April 9, 2007 codeprojectfollowing the link shows these values. I have not tested them.vbscript-->Function GetFileType(sFile) dot = InStrRev(sFile, ".") filetype=2 If dot > 0 Then sExt = LCase(Mid(sFile, dot + 1, 3)) If sExt = "bmp" Then filetype = 0 If sExt = "gif" Then filetype = 1 If sExt = "jpg" Then filetype = 2 If sExt = "png" Then filetype = 3 If sExt = "ico" Then filetype = 4 If sExt = "tif" Then filetype = 5 If sExt = "tga" Then filetype = 6 If sExt = "pcx" Then filetype = 7 GetFileType=filetypeEnd Function Link to comment Share on other sites More sharing options...
luvmachine Posted April 9, 2007 Share Posted April 9, 2007 Well I just used my previous code and replaced the '2' with a '6' under Load() and Save() but it didn't do so properly, took the image from 3.8mb to 0 bytes :\ thank you for the post though. 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