[英]Rotating an NSImageCell
我正在一個項目中,我有一個很大的NSMatrix
NSImageCells
。 我需要在其單元格中旋轉特定的單個Images
(或者甚至旋轉單元格本身,因為它看起來是一樣的)。 每個像元和圖像都是40x40的正方形,因此不必調整大小,因為我將堅持90度的增量。 問題是,因為我使用的是NSImageCells
而不是NSImageViews
,所以無法使用setFrameCenterRotation:
輕松旋轉圖像。 有人知道我該怎么做嗎?
對於仍在尋找實現此目的的方法的人,因為我是用ASOC編寫的,所以最終使用了以下代碼:
on rotateImage_byAngle_(startingImage, angle)
set rotated to current application's NSImage's alloc()'s initWithSize_({startingImage's |size|()'s height(), startingImage's |size|()'s |width|()})
rotated's lockFocus()
set transform to current application's NSAffineTransform's transform()
transform's translateXBy_yBy_((rotated's |size|()'s |width|()) / 2, (rotated's |size|()'s height()) / 2)
transform's rotateByDegrees_(angle)
transform's translateXBy_yBy_(-(rotated's |size|()'s height()) / 2, -(rotated's |size|()'s |width|()) / 2)
transform's concat()
startingImage's drawAtPoint_fromRect_operation_fraction_({0, 0}, {{0, 0}, {0, 0}}, current application's NSCompositeCopy, 1)
rotated's unlockFocus()
return rotated
end rotateImage_byAngle_
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.