[Resolution]解像度を求める
たぶん、もっとスマートな方法があるに違いない
#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions
property objMe : a reference to current application
property objNSString : a reference to objMe's NSString
property objNSImage : a reference to NSImage
property objNSBitmapImageRep : a reference to NSBitmapImageRep
######ログ表示
doLogView()
###動作確認している分だけ
set listUTI to {"public.jpeg", "public.png", "org.webmproject.webp", "public.heic", "public.bmp"}
###ダイアログのデフォルトロケーション
tell application "Finder"
## set aliasDefaultLocation to container of (path to me) as alias
set aliasDefaultLocation to (path to desktop folder from user domain) as alias
end tell
###ダイアログ
set aliasFile to (choose file with prompt "ファイルを選んでください" default location (aliasDefaultLocation) of type listUTI with invisibles and showing package contents without multiple selections allowed) as alias
###エイリアスをUNIXパスに
set strFilePath to POSIX path of aliasFile as text
####NSBitmapImageRepの処理
set ocidBitmapImageRepObj to (objNSBitmapImageRep's imageRepWithContentsOfFile:strFilePath)
###高
set numImageRepHight to ocidBitmapImageRepObj's pixelsHigh() as integer
###幅
set numImageRepWide to ocidBitmapImageRepObj's pixelsWide() as integer
####ピクセル数
set numImageRepBytePerPlane to (numImageRepHight * numImageRepWide) as integer
log numImageRepHight
log numImageRepWide
log numImageRepBytePerPlane
#####NSImageの処理
set ocidNSImageFileObj to (objNSImage's alloc()'s initWithContentsOfFile:strFilePath)
set recordSize to (ocidNSImageFileObj's |size|()) as record
###高
set numNSImageHeight to height of recordSize as integer
###幅
set numNSImageWidth to width of recordSize as integer
####ピクセル数
set numNSImageBytePerPlane to (numNSImageHeight * numNSImageWidth) as integer
log numNSImageHeight
log numNSImageWidth
log numNSImageBytePerPlane
####解像度を求める
set numResolution to (((numImageRepBytePerPlane / numNSImageBytePerPlane) ^ 0.5) * 72) as integer
log numResolution
#########################ログ表示
to doLogView()
tell application "System Events"
set listAppList to title of (every process where background only is false)
end tell
repeat with objAppList in listAppList
set strAppList to objAppList as text
if strAppList is "スクリプトエディタ" then
tell application "Script Editor"
if frontmost is true then
try
tell application "System Events" to click menu item "ログを表示" of menu "表示" of menu bar item "表示" of menu bar 1 of application process "Script Editor"
end try
end if
end tell
end if
end repeat
end doLogView
#########################
| 固定リンク
「NSBitmapImageRep」カテゴリの記事
- [AppleScript OC ・NSImage]画像の解像度変更 修正(2024.04.07)
- [2in1]画像合成2in1 2up 右→左順(2024.03.21)
- Gifを全コマ別PNGに書き出し (フレーム数0の場合を考慮した修正)(2024.02.01)
- [NSBitmapImageRep] 処理一覧(2024.02.29)
- 画像を生成する(2024.02.16)