AutoHotkey Community

It is currently May 27th, 2012, 12:26 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: January 13th, 2009, 8:18 am 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
WIA requires XPSP1 or higher.
http://msdn.microsoft.com/en-us/library/ms630827.aspx

In this script, I'll convert a BMP/JPG/PNG/GIF/TIF image file into a different format image file, as an alternative to GDI+ solution Convert() in the script ScreenCapture.

But can use for other purposes too. For example:
http://msdn.microsoft.com/en-us/library/ms630819.aspx

NEED: COM Standard Library.

Code:
; Allowed extensions for sFileTo: BMP/JPG/PNG/GIF/TIF
sFileFr   := A_ScriptDir . "\screen.jpg"
sFileTo   := A_ScriptDir . "\screen.bmp"
;nQuality:= 95   ; for JPG only

FormatBMP   := "{B96B3CAB-0728-11D3-9D7B-0000F81EF32E}"
FormatJPG   := "{B96B3CAE-0728-11D3-9D7B-0000F81EF32E}"
FormatPNG   := "{B96B3CAF-0728-11D3-9D7B-0000F81EF32E}"
FormatGIF   := "{B96B3CB0-0728-11D3-9D7B-0000F81EF32E}"
FormatTIF   := "{B96B3CB1-0728-11D3-9D7B-0000F81EF32E}"

WIA_Convert(sFileFr, sFileTo, nQuality)
Return

WIA_Convert(sFileFr, sFileTo, nQuality = "")
{
   SplitPath, sFileTo,,, sExtTo
   COM_Init()
   IMG :=  COM_CreateObject("WIA.ImageFile")
   IP  :=  COM_CreateObject("WIA.ImageProcess")
   COM_Invoke(IP,"Filters.Add",COM_Invoke(IP,"FilterInfos['Convert'].FilterID"))
   COM_Invoke(IP,"Filters[1].Properties['FormatID'].Value",Format%sExtTo%), sExtTo!="JPG"||nQuality=="" ? "":COM_Invoke(IP,"Filters[1].Properties['Quality'].Value",nQuality)
   COM_Invoke(IMG,"LoadFile",sFileFr)
   IMG := (COM_Invoke(IP,"Apply","+" IMG),COM_Release(IMG))
   COM_Invoke(IMG,"SaveFile",sFileTo)
   COM_Release(IMG)
   COM_Release(IP)
   COM_Term()
}


Last edited by Sean on February 20th, 2009, 6:07 am, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 19th, 2009, 2:37 pm 
:shock:
awesome!

possible to preview pics from any digital image devices before saving, finally an alternative to crappy scanner softwares! :D


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: February 20th, 2009, 2:31 am 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
Thanks. As a side note, while writing an example code of this, I actually felt the need of the dot syntax, even in a limited form, which has been incorporated into COM_Invoke() recently. BTW, I can easily remove the limit of one index, but I'd like to enforce a rule on users with that and there still remain issues like delimiters handling etc, I'd rather leave it as is now.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], Bon, SKAN, Yahoo [Bot] and 5 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group