Jump to content

cxImageAlt image manipulations


Will66
 Share

Recommended Posts

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 etc

Asp examples: http://www.google.com.au/search?hl=en&...earch&meta=

CxImageATL.dll

CxImageATL.au3

CxImageALT.au3

#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 by Will66
Link to comment
Share on other sites

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

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

  • 2 weeks later...

Screen Shot example:

Const $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

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

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

Edit: btw in an above post it shows png as type 3, I believe it is actually type 0

Edited by Will66
Link to comment
Share on other sites

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

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

EndIf

But I don't know what $Color is supposed to be (what is RGBQUAD type?). And perhaps there is something else wrong.

Edited by SmiLe
Link to comment
Share on other sites

  • 2 weeks later...

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

Link to comment
Share on other sites

  • 1 month later...

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_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: 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 Program

AutoIt_Icon_small.pngUDFs: 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
 
AutoIt_Icon_small.pngExamples: 
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 AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

  • 2 weeks later...

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

codeproject

following 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=filetype

End Function

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