Domanda

I need to create a very simple image cropping interface for an OS X cocoa application, but I am not sure where to start. The user needs to be able to choose a crop size from a menu of presets, be presented with a cropping rectangle that can be resized preserving the ratio, and moved around the image until they finally apply the selected crop to the image.

I've done some searching for sample code and projects but not found anything too useful. Core Image fun house has some pointers but is a retired sample. There are lots of iOS examples, but I've not found an easy to follow Mac OS example.

Can someone point me in the right direction (or at a sample project or framework!!).

Thanks a lot.

È stato utile?

Soluzione

Here is a project you can look at:

https://github.com/foundry/drawingtest

It's a little demo I made as I was trying to understand the relationship between the rects in this method:

- (void)drawInRect:(NSRect)dstRect 
          fromRect:(NSRect)srcRect 
         operation:(NSCompositingOperation)op 
          fraction:(CGFloat)delta

Note that the older compositeToPoint: methods are deprecated and should not be used for this sort of thing.

srcRect is the portion of the original image (in it's own coordinates) that you want to keep.

dstRect is the rect that you want that cropped area to draw into.

JMRect in the project is an NSObject representation of an NSRect - so that we can use cocoa bindings to tie the interface controls together.

For your UI, the cropping rectangle could just be a transparent subview view with a border that you push around and resize over the image you want to crop.

This is by no means a complete solution to your question, but it's something you can poke around with - it might help you to get started.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top