Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.
Keywords: udfMakeIcon ImgSample Make Icon convert BMP JPG ICO .BMP .JPG .ICO bitmap
#DefineFunction udfMakeIcon(infile, outfile) ;*************************************************************************** ;** ;** udfMakeIcon ;** ;** Purpose: Convert BMP/JPG to ICO file ;** Inputs: BMP/JPG File ;** Outputs: ICO File ;** ;** REQUIREMENTS: PIXIE Extender [WWIMG44I.DLL] ;** ;** NOTE: The icon created with this code will not work with the WinBatch+Compiler. ;** The WinBatch+Compiler requires specially formatted .ICO files. ;** ;** Revisions: 1.0 Deana Falk / Garry Nichol ;** ;*************************************************************************** ; Check for valid input parameters If !FileExist( infile ) Then Return 0 If !DirExist( FilePath( outfile ) ) Then Return 0 If FileExist( outfile ) Then FileDelete( outfile ) If StrUpper(FileExtension( outfile ) ) != 'ICO' Then Return 0 ; Load the PIXIE Extender AddExtender("WWIMG44I.DLL") ; Temporarily save the file as a .BMP tempfile = FilePath( outfile ) : FileRoot( outfile ) : '.bmp' ; Use ImgSample to save the file as a 256x256 bitmap width = 256 height = 256 result = ImgSample( infile, tempfile, width, height ) ; Rename and delete the temporary file FileRename( tempfile, outfile ) ;Success Return @TRUE #EndFunction ;; ~~~~~~~~~~~~~~~~~~~~~~~~~~ ;; Test: Bad input file path ;; ~~~~~~~~~~~~~~~~~~~~~~~~~~ ;img = 'X:\xxx\yyy.ext' ;ico = 'D:\Deana\My Pictures\Test\':FileRoot(img):'.ico' ;ret = udfMakeIcon( img, ico ) ;if !ret ; Pause('Notice', 'udfMakeIcon Failed!') ; exit ;endif ;Run( 'Explorer', FilePath( ico ) ) ;; ~~~~~~~~~~~~~~~~~~~~~~~~~~ ;; Test: Bad output file extension ;; ~~~~~~~~~~~~~~~~~~~~~~~~~~ ;img = AskFileName( 'Choose file to Convert to ICO', 'C:\', 'BMP|*.bmp;JPG|*.jpg;', 'C:\Documents and Settings\All Users\Application Data\Microsoft\User Account Pictures\Default Pictures\snowflake.bmp',1) ;ico = 'D:\Deana\My Pictures\Test\':FileRoot(img):'.ico' ;ret = udfMakeIcon( img, ico ) ;if !ret ; Pause('Notice', 'udfMakeIcon Failed!') ; exit ;endif ;Run( 'Explorer', FilePath( ico ) ) ; ~~~~~~~~~~~~~~~~~~~~~~~~~~ ; Convert BMP to .ICO ; ~~~~~~~~~~~~~~~~~~~~~~~~~~ img = AskFilename( 'Choose BMP to Convert to ICO', 'C:\', 'BMP|*.bmp', 'C:\Documents and Settings\All Users\Application Data\Microsoft\User Account Pictures\Default Pictures\snowflake.bmp',1) ico = 'D:\Deana\My Pictures\Test\':FileRoot(img):'.ico' ret = udfMakeIcon( img, ico ) If !ret Pause('Notice', 'udfMakeIcon Failed!') Exit EndIf ; ~~~~~~~~~~~~~~~~~~~~~~~~~~ ; Convert JPG to .ICO ; ~~~~~~~~~~~~~~~~~~~~~~~~~~ img = AskFilename( 'Choose JPG to Convert to ICO', 'C:\', 'JPG|*.jpg', '',1) ico = 'D:\Deana\My Pictures\Test\':FileRoot(img):'.ico' ret = udfMakeIcon( img, ico ) If !ret Pause('Notice', 'udfMakeIcon Failed!') Exit EndIf ; Display results in Windows Explorer Run( 'Explorer', FilePath( ico ) ) Exit
Article ID: W18349
Filename: udfMakeIcon - Convert BMP or JPG to ICO file.txt
File Created: 2009:07:17:11:14:56
Last Updated: 2009:07:17:11:14:56