How to use with Autoit

Discussions on GFL SDK, the graphic library for reading and writing graphic files

Moderators: XnTriq, helmut, xnview

nobbe
Posts: 3
Joined: Fri Jun 08, 2007 2:00 am

How to use with Autoit

Post by nobbe »

hello all

this is my first post because i use the SDK with autoit and wanted to share this with you

http://www.autoitscript.com/autoit3/

setting the correct color code gave me a hard time to convert into OLE_COLOR

nob

Code: Select all

;
;
; light image converter
; using nconvert ACTIVEx now
;
; to register the active X control do this :
;  copy GflAx.dll c:\winnt\system32
;  regsvr32.exe GflAx.dll
;
; author nobbe, june 2007
;
;
#include <GUIConstants>

$Form1 = GUICreate("nconvert sample", 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>pic_Open



;
; just resample the picture 1/4 of its orig size and save with diff qualities
;
Func resample($file, $Width1, $Height)
	
	; the nconvert GFX api - if this fails you need to register the control first
	$imgObject = ObjCreate("GflAx.GflAx")


	$imgObject.LoadBitmap ($file);

	$widthOrig = $imgObject.Width ()
	$heightOrig = $imgObject.Height ()

	;MsgBox(0, "", $widthOrig & "x" & $heightOrig)

	$widthTh = Int($widthOrig / 4) ; 1/4 of original
	$heightTh = Int($heightOrig / 4)


	; set text to image 
	$imgObject.FontName = "Times New Roman"
	$imgObject.FontSize = 250;
	
;OLE_COLOR Encoding
;The OLE_COLOR format is quite straightforward. The best way to think about it is as an eight-bit hexadecimal number. The first two bits are reserved and must always be 0. The second two bits represent the blue value, the next two represent the green value and the last two represent the red values. So for example, RGB(5, 100, 255) would be encoded as:

;000564FF (hex) or 353535 (decimal)

;A quick equation for RGB to OLE_COLOR is:
;var olecolor = red + (green * 256) + (blue * 65536);	
	
	; original RGB colors 
	$r=36;
	$g=38;
	$b=154;
	
	$red   	= StringMid(hex($r), 7, 2) ; "000000ff";
	$green  = StringMid(hex($g), 7, 2) ; 
	$blue   = StringMid(hex($b), 7, 2) ; 
	
	$Color = "&H00" & $blue & $green & $red ; force OLE_COLOR INTO - BGR mode.. 
    $imgObject.TextOut ("Test abcdefg", 100, 400, $Color) ; OLE_COLOR 


	; resize object
	$imgObject.Resize ($widthTh, $heightTh)
	$imgObject.SaveFormat = 1 ; jpeg

	$imgObject.SaveJPEGQuality = 100 ; 100 % quality
	$imgObject.SaveBitmap (@ScriptDir & "\100_a.jpg")

	$imgObject.SaveJPEGQuality = 70 ;  % quality
	$imgObject.SaveBitmap (@ScriptDir & "\70_a.jpg")

	$imgObject.SaveJPEGQuality = 40 ;  % quality
	$imgObject.SaveBitmap (@ScriptDir & "\40_a.jpg")

	$imgObject.SaveJPEGQuality = 10 ;  % quality
	$imgObject.SaveBitmap (@ScriptDir & "\10_a.jpg")
	
EndFunc   ;==>resample