Tonec.com Bringing Internet Technology Innovations to Market since 1991
  News Products Outsourcing About Us Contact Us
what's new?what's new? featuresfeatures samplessamples manualmanual downloaddownload buybuy
  Tonec Homepage
ProductsActive Imagesamples

Please view complete list of samples

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)

Next sample >> 

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

  Privacy Policy
  © 1999-2005. Tonec, Inc. All rights reserved.