Does anyone know a function that allows you to pass an X,Y pixel co-ords and then the function returns the Color(in any format, #FF00FF, RGB, etc) of the specified pixel.
Only problem is that it costs $300 US. Anyone know of a slightly less costly (free ) solution? "The surest sign that intelligent life exists elsewhere in the universe is that it has never tried to contact us"
Bill Watterson, Calvin & Hobbes
Good question - I am looking forward to the answers.
But what's wrong with Damian13's link?
It produces the following:
Main Page SDK Reference Guide Examples
PixelColor
The PixelColor property sets or returns the color of the specified pixel in the image.
Syntax :
[COLOR== ] imageObj.PixelColor(XPos, YPos) [ = Color ]
Parameters
imageObj
The variable that contains reference to VIMAS.Image object.
XPos, YPos
The horizontal and vertical position of the specified pixel.
Color
The variable that contains color value of the pixel.
This variable allocates 4 bytes (double word).
The Color variable is compatible with OLE_COLOR type and contains pixel color in the RGB format.
----------------------
|31-24|23-16|15-8|7-0|
----------------------
| | | |
| | | +----> Blue 8 bit (0-255)
| | +--------> Green 8 bit (0-255)
| +--------------> Red 8 bit (0-255)
+--------------------> Transparency (Alpha channel) 8 bit (0-255)
When Transparency byte is 0 the pixel is opaque. When it`s 255 the pixel is completely transparent.
Remarks
The PixelColor property can be used for TrueColor 24 bits/pixel images only. If your image is not TrueColor you can convert it into TrueColor colormap mode.
Example (VisualBasic)
' create VIMAS.Image object
Set myImage = CreateObject("VIMAS.Image"
' load image file in the object
fileSize = myImage.Load("c:\temp\003.bmp"
if not myImage.Colormap = imgColor_24 then
' convert image into TrueColor mode
Call myImage.Edit("RGB24", "", ""
endif
Dim Color As OLE_COLOR
' get color of the pixel in 0,0 position
Color = myImage.PixelColor(0, 0)
' retrieve Alpha, Red, Green, Blue components of the color
If Color < 0 Then
Color = 2147483647 + Color + 1
Alpha = Color \ (2 ^ 23)
Color = Color - Alpha * (2 ^ 23)
Alpha = Alpha + 1
Else
Alpha = Color \ (2 ^ 24)
Color = Color - Alpha * (2 ^ 24)
End If
Red = Color \ (2 ^ 16)
Color = Color - Red * (2 ^ 16)
Green = Color \ (2 ^ 8)
Blue = Color - Green * (2 ^ 8)
' set red color of the pixel in the position 10,10
Color = &HFF0000
myImage.PixelColor(10, 10) = Color
' set green color of the pixel in the position 20,20
Color = &HFF00
myImage.PixelColor(20, 20) = Color
' set gray color of the pixel in the position 30,30
Color = &H808080
myImage.PixelColor(30, 30) = Color
Example (JavaScript)
var myImage = new ActiveXObject("VIMAS.Image"
// load image file in the object
fileSize = myImage.Load("c:\\temp\\003.bmp"
// get color of the pixel in 0,0 position
var Color = myImage.PixelColor(0,0);
// retrieve Alpha, Red, Green, Blue components of the color
Alpha = (Color >> 24) & 0xFF;
Red = (Color >> 16) & 0xFF;
Green = (Color >> 8) & 0xFF;
Blue = Color & 0xFF;
// set red color of the pixel in the position 10,10
myImage.PixelColor(10,10) = 0xFF0000;
// set green color of the pixel in the position 20,20
myImage.PixelColor(20,20) = 0x00FF00;
// set gray color of the pixel in the position 30,30
myImage.PixelColor(30,30) = 0x808080;
See Also :
How to handle VIMAS.Image errors in the : VisualBasic, JavaScript, C,C++
VIMAS.Image methods : PaletteColor, ClormapType, PixelIndex
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.