指定画像の指定座標のピクセルの色を8ビットRGB値で返すAppleScriptです。
使用する座標系は左上が{0,0}です。
AppleScript名:指定画像の指定座標の色情報をRGBで取得.scptd |
— – Created by: Takaaki Naganoya – Created on: 2018/11/15 — – Copyright © 2018 Piyomaru Software, All Rights Reserved — use AppleScript version "2.4" — Yosemite (10.10) or later use framework "Cocoa" –Foundation + AppKit use scripting additions property NSImage : a reference to current application’s NSImage property NSBitmapImageRep : a reference to current application’s NSBitmapImageRep set aFile to POSIX path of (choose file of type {"public.image"}) set {xNum, yNum} to {0, 0} set cRes to getColorRGBNumFromImageByPosition(aFile, xNum, yNum) of me –> {255, 0, 0} on getColorRGBNumFromImageByPosition(aFilePath, xPos as integer, yPos as integer) set anNSImage to NSImage’s alloc()’s initWithContentsOfFile:aFilePath set aRawimg to NSBitmapImageRep’s imageRepWithData:(anNSImage’s TIFFRepresentation()) set aColor to (aRawimg’s colorAtX:xPos y:yPos) set aRed to (aColor’s redComponent()) * 255 set aGreen to (aColor’s greenComponent()) * 255 set aBlue to (aColor’s blueComponent()) * 255 return {aRed as integer, aGreen as integer, aBlue as integer} end getColorRGBNumFromImageByPosition |
More from my site
(Visited 261 times, 1 visits today)