WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Pixie (obsolete)
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Convert to Grayscale

 Keywords: greyscale black and white B&W colour

Question:

How can an color image be converted to black and white

Answer:

Use the Pixie Extender.

AddExtender("wwimg34i.dll")
Bright= 100 ;no adjustment
Sat= 0 ;grayscale 
Hue= 100 ;no adjustment
BSH=StrCat(Bright,",",Sat,",",Hue)

infile="color.jpg"
outfile="BlackandWhite.jpg"

ImgModulate(infile,outfile,BSH) ;Brightness, Saturation, Hue


User Reply:

I tried the pixie extender and it does a nice job but it doesn't convert 24 bit to 8 bit.

Answer:

I think it does if you're converting JPG's or GIF's to black and white. I'm guessing you're converting a BMP, though? To make it an 8-bit black and white BMP, try this code:
AddExtender("WWIMG44I.DLL")

Bright= 100 ;no adjustment
Sat= 0 ;grayscale
Hue= 100 ;no adjustment
BSH=StrCat(Bright,",",Sat,",",Hue)
infile ="color.bmp"
outfile="blackandwhite.bmp"

ImgModulate(infile,outfile,BSH) ;Convert to black-and-white

  ;this will convert it to 8-bit (256 colors)
ext = StrUpper(FileExtension(outfile))
If ext!="JPG" && ext!="GIF"  ;if we didn't already convert to a JPG or GIF, then do so now
  outfile_8bit=StrCat(FileRoot(outfile),".gif") ;GIF looks better than a JPG
  ImgConvert(outfile,outfile_8bit) ;convert to a black-and-white GIF...should be 256 colors now
  ImgConvert(outfile_8bit,outfile) ;convert it back to its original format...should stay 256 colors
  FileDelete(outfile_8bit)  ;remove temporary GIF
EndIf
or, even cleaner (ImgModulate can convert at the same time...this way only requires one call to ImgConvert):
AddExtender("WWIMG44I.DLL")

Bright= 100 ;no adjustment
Sat= 0 ;grayscale
Hue= 100 ;no adjustment
BSH=StrCat(Bright,",",Sat,",",Hue)
infile ="color.bmp"
outfile="blackandwhite.gif"  ;make the outfile a GIF

ImgModulate(infile,outfile,BSH) ;convert to black and white GIF...should be 8-bits now (256 colors)
ImgConvert(outfile,StrCat(FileRoot(outfile),".bmp")) ;convert it back to BMP...should stay 256 colors
FileDelete(outfile)  ;remove temporary GIF


Article ID:   W16843
File Created: 2014:01:29:15:34:52
Last Updated: 2014:01:29:15:34:52