🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: adobe.photoshop.scripting
Article #448

Re: JavaScript: Get color of a defined Pixel

#448
From: Andreas_Kr�ger
Date: Sat, 31 Jan 2009 20:54
37 lines
1708 bytes
Hi Robin,

I have this script for scanning a picture for colored pixels. This works fine for me.
I hope it will help you

var myDoc = app.activeDocument;

if(myDoc.mode != DocumentMode.GRAYSCALE && myDoc.mode != DocumentMode.BITMAP){

	var docWidth = myDoc.width;
	var docHeight = myDoc.height;
	var xPos = 0;
	var yPos = 0;

	app.activeDocument.colorSamplers.removeAll();
	var pixelLoc = [UnitValue(0) , UnitValue(0)];
	var myColorSampler = app.activeDocument.colorSamplers.add(pixelLoc);

	for(xPos = 0; xPos <= docWidth; xPos++) 	{ 		var myColor = myColorSampler.color; 		var hsb_H = myColor.hsb.hue; 		var hsb_S = myColor.hsb.saturation; 		var hsb_B = myColor.hsb.brightness; 		//$.writeln (hsb_H + "/" + hsb_S + "/" + hsb_B) 		if( hsb_H != 0 || hsb_S != 0){ 			alert("Bild ist farbig!"); 			break;}

		if(xPos == docWidth)
		{
			xPos = 0;
			yPos++;
			if(yPos == docHeight){
				alert("Bild ist ein Graustufenbild.");
				break;
			}
			pixelLoc[1] = yPos;
		}
		else
		{
			myColorSampler.move(pixelLoc);
			pixelLoc[0] = xPos;
		}
	}
}
Technical Details
Message-ID: <59b7700a.4@webcrossing.la2eafNXanI>
Path: arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!news.glorb.com!news2.glorb.com!newshub.sdsu.edu!webcrossing
References: <59b7700a.-1@webcrossing.la2eafNXanI>

Show Full Headers
Complete Article Headers
X-Google-Thread: f5839,e4d892495c466347
X-Google-Attributes: gidf5839,domainid0,public,usenet
X-Google-Language: ENGLISH,ASCII-7-bit
From: Andreas_Kr�ger@adobeforums.com
Path: arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!news.glorb.com!news2.glorb.com!newshub.sdsu.edu!webcrossing
Newsgroups: adobe.photoshop.scripting
Subject: Re: JavaScript: Get color of a defined Pixel
Message-ID: <59b7700a.4@webcrossing.la2eafNXanI>
Date: Sat, 31 Jan 2009 12:54:07 -0800
References: <59b7700a.-1@webcrossing.la2eafNXanI>
Lines: 48
MIME-Version: 1.0
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit