GetPixel support in JScript

Kowboy87

Member
Joined
Aug 26, 2003
Messages
5
According to the MSDN Refence Library I should be able to use GetPixel when attempting to return the color of a particular pixel in a specifiec bitmap.

Unfortunately I get an error saying a ";" is expected when I run the following line ...

var imageObj = new Bitmap(strMaster));

Can anyone help me with what I am doing wrong other than using JScript for something I should be using C# to accomplish? Trust me, Id prefer to use C# but the automated test harness were using only accepts JScript.
 
Compare the number of opening parenthesis to the number of closing parenthesis and youll see they dont match. Remove the duplicate closing parenthesis.
 
Thanks, I removed the extra parentheses and wound up with an error stating I Bitmap was undefined. It looks like JScript is treating Bitmap as an undefined function. Im thinking I might need to create a new ActiveXObject accessing a bitmap through an application like MSPaint using the code such as

var imageObj = new ActiveXObject("MSPaint.Application");

but then again I could also create a new object class inheriting from Image and including the structure of a Bitmap but that seems to be a little like reinventing the wheel. Also, Im unsure as to whether .Application will work with MSPaint since its not usually considered an Office application.

Does anyone have any fresh ideas as to how I can extract the color of a pixel from a bitmap using JSCript cause Im starting to get frustrated.

Thanks.
 
System.Drawing.Bitmap will work in JScript? I should probably mention Im accessing this through the Windows scripting host and not an ActiveX instance like IE6.x or solmething else.
 
I honestly dont know anything about JScript, but Im assuming that youre using the .NET framework and GDI+ (since thats the area you posted in). In which case, System.Drawing is where the Bitmap class is located.
 
I dont think WSH supports .NET unless theyve improved it. The JScript is just what youd get in the browser, but with more rights (to create objects and such without any security popups).

I cant remember offhand the names of the objects you want - havent used COM in over a year now :) - but its something like:
Code:
var imageObj = new ActiveXObject("stdole.StdPicture");
imageObj = LoadPicture("filename")

Im about 80% sure the StdPicture is what you want. LoadPicture might be a VBScript specific function, if it even exists there. I know it works in VB6 :)

Anyway, Im still not sure how youd get a pixel from the StdPicture object.

What are you trying to do with WSH that you need to get a pixel? Is this trying to look at another window and get the pixels? If so, youre likely to need the API which I dont think is available in WSH. You might be better off coding this whole thing in either VB6 or at least making a VB6 DLL that you can then use from WSH.

Id suggest .NET, but I believe youd have to code your .NET DLL to be a COM DLL which is probably more work than you want :)

-Nerseus
 
Back
Top