我是可可的新手,我對NSImage有一些疑問。更改邊界原點+裁剪圖像
問題1:
更改圖像的邊界起源似乎沒有任何效果。我預計這幅圖像是從新設置的起源中得出的,但似乎並非如此。我錯過了什麼嗎?
代碼:
NSImage* carImage = [NSImage imageNamed:@"car"];
[self.imageView setImage:carImage];
//Following line has no effect:
self.imageView.bounds = CGRectMake(self.imageView.bounds.origin.x + 100, self.imageView.bounds.origin.y, self.imageView.bounds.size.width,self.imageView.bounds.size.height);
注意:ImageView的是一個IBOutlet
問題2:
我試圖裁剪圖像,但它似乎沒有不裁剪圖像,我可以看到完整的圖像。我錯過了什麼?
代碼:
NSRect sourceRect = CGRectMake(150, 25, 100, 50);
NSRect destRect = CGRectMake(0, 0, 100, 50);
NSImage* carImage = [NSImage imageNamed:@"car"];
[carImage drawInRect:destRect fromRect:sourceRect operation:NSCompositeSourceOver fraction:1.0];
[self.imageView setImage:carImage];
感謝
非常感謝彼得,你的回答真的很有幫助! – user1046037 2012-01-30 01:26:27