Rotation on NSImage in NSMatrix

Does anybody know if it is possible to have a rotation like 90º on a NSImage that is part of a NSMatrix?

What do you mean by “NSImage that is part of a NSMatrix”. Where is the image? Are the matrix’s cells NSImageViews or NSButtons with images in them, or something else?

Ric

Sorry for the confusion. I Don’t understand the code that I am using all that well. I found a example that did what I wanted. Here is the code in Question. I hope it helps answer you question. What happens is a image is selected, and it is previewed x amount across and x amount down based on two different text field values.

so if text field 1 has a 2 entered in it and text field 2 has a 3 entered in it you will get a preview of the file that is stepped out 2 across and 3 down. Im looking to be able to control the rotation of each of the previews with the content of a popup that has values of 45º, 90º etc…


set myCell to current application's NSButtonCell's alloc()'s init()
			myCell's setBordered_(0)
			set newImpoImage to NSImage's alloc()'s initWithContentsOfFile_(ImageFile) --(ImpoImageFill)
			myCell's setImage_(newImpoImage)
			myCell's setImageScaling_(0)
			set stepVforPreview to (stepV's stringValue() as real)
			set stepHforPreview to (stepH's stringValue() as real)
			set StepMatrix to current application's NSMatrix's alloc()'s initWithFrame_mode_prototype_numberOfRows_numberOfColumns_({{0, 0}, {147, 142}}, 0, myCell, stepVforPreview, stepHforPreview)
			StepMatrix's setAutosizesCells_(1) 
			myCell's setImageScaling_(0)
			StepMatrix's setTarget_(me)
			StepMatrix's setAction_("click")
			StepMatrix's setDrawsBackground_(1)
			cView's addSubview_(StepMatrix)

Rotating an NSImage isn’t exactly straight forward, especially if not in 90-degree increments. You have yo make a new image, transform it, and draw the old image into it.

There’s some Objective-C code here http://www.cocoabuilder.com/archive/cocoa/231334-rotate-nsimage-to-get-new-nsimage-without-drawing.html#231362 for a category on NSImage that makes it a one-liner. Is that what you are after?

Thank you Shane, This worked like a charm.

Added 2 C files and called them out with a line like this

set newImage to anImage’s imageRotatedByDegrees_(45)

resulting in code that looks like this :slight_smile:

set RotationValue to (theRotation's titleOfSelectedItem() as string)
			set AppleScript's text item delimiters to "º"
			set theitems to text items of RotationValue
			set AppleScript's text item delimiters to ""
			set RotationValue to item 1 of theitems as string
			set myCell to current application's NSButtonCell's alloc()'s init()
			myCell's setBordered_(0)
			set newImpoImage to NSImage's alloc()'s initWithContentsOfFile_(ImageFile) --(ImpoImageFill)
		-- New solution to rotation issue
	set rotationAmount to RotationValue
			set newImage to newImpoImage's imageRotatedByDegrees_(RotationValue)
			
myCell's setImage_(newImage)
			myCell's setImageScaling_(0)
			set stepVforPreview to (stepV's stringValue() as real)
			set stepHforPreview to (stepH's stringValue() as real)
			set StepMatrix to current application's NSMatrix's alloc()'s initWithFrame_mode_prototype_numberOfRows_numberOfColumns_({{0, 0}, {147, 142}}, 0, myCell, stepVforPreview, stepHforPreview)
			StepMatrix's setAutosizesCells_(1) --Makes the cells fill the whole frame of the matrix set in the init method
			myCell's setImageScaling_(0)
			StepMatrix's setTarget_(me)
			StepMatrix's setAction_("click")
			StepMatrix's setDrawsBackground_(1)
			cView's addSubview_(StepMatrix)