Home... About... Arrange... FAQ... Customers...

Sample 22 - Replacing colors and creating transparency

The sample shows how to load JPEG image from file, convert it to Palette image and change colors of all pixels where red value is less than 72 to black transparent color

Threshold.vbs



Dim im
Set im = CreateObject("ActiveImage.Images.1")
'im.CreateImagePalette 300,400
im.SetImageType 1
im.ReadFromFile "C:\AI\rose.jpg" 

im.ConvertToPaletteNoAlpha

width = im.GetWidth
height = im.GetHeight

colorbk_r = 0
colorbk_g = 0
colorbk_b = 0

Threshold  = 72

For x = 0  to width
 for y = 0 to height


  r = im.GetPixelRed(x,y)
  g = im.GetPixelGreen(x,y)
  b = im.GetPixelBlue(x,y)
  if r < Threshold  then 
    im.SetColor colorbk_r, colorbk_g, colorbk_b
    im.SetPixel x,y
  end if
 next
next 

im.SetColor colorbk_r, colorbk_g, colorbk_b
im.SetTransparent 1
im.SetSaveAlpha 0


im.SetImageType 3
im.WriteToFile "C:\AI\Threshold.gif"
im.SetImageType 0
im.WriteToFile "C:\AI\Threshold.png"

im.DestroyImage
Set im = Nothing
 


Picture 1. rose.jpg (size - 6,3Kb) Picture 1. Threshold.gif (size - 11,4Kb)


If you have any questions or bug reports, write to active.image@tonec.com for technical support.


© 2000-2001 All Rights Reserved

Tonec Inc., 16835 Algonquin Street #400, Huntington Beach, CA, 92649, fax: (509) 752-1450, e-mail: info@tonec.com