Frage

In my project I have an NSImageView and I drop a picture from the finder on it. In an IBAction I want to take care if the picture size is bigger than the dimensions of the NSImageView as shown below.

I hoped that sender.size or sender.size.x or sender.size.width would give me the size of the NSImageView imageDropped but it doesn't.

Any ideas how I can get the dimensions of the NSImageView?

- (IBAction)imageWasDropped:(id)sender {
   NSImage *theImage = [imageDropped image];

   NSLog(@"%@", sender); // this returns <NSImageView: 0x10011d210>

   NSSize _dimensions = [theImage size];

  if (_dimensions.width > sender.size){

  }

   [imageOriginal setImage:theImage];
   [picture_1 setImage:theImage];

}
War es hilfreich?

Lösung

This is very Simple, _imageView the outlet name of that imageWell where you drop or display your image.

NSLog(@"%f, %f", [[_imageView image]size].height, [[_imageView image]size].width);

EDIT:

For imageWell Size:

NSLog(@"Image well size is  :%f x %f",[_imageView frame].size.height, [_imageView frame].size.width);
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top