您的位置:首页 > 其它

第18章 Images and Mouse Events

2012-05-25 18:48 197 查看
第18章 Images and Mouse Events

本章主要介绍如何将一个image放到view中,以及使用鼠标的响应事件完成重新绘制图像的功能。

在上一章custom view的基础上,响应菜单栏的open事件,打开一个openPanel,完成选择图像文件,并将该图像存储到内部变量中。在自己创建的strechview绘制自己时,通过响应鼠标的事件,完成在选定位置,选定大小的矩形中绘制选择的图像文件。

在challenge中,又一次使用NSBezierPath,完成在任意位置绘制圆的功能。



view绘制图像函数

- (void)drawRect: (NSRect)rect {

// Drawing code here.

NSRect bounds = [self bounds];

[[NSColor greenColor] set];

[NSBezierPath fillRect:bounds];

[[NSColor whiteColor] set];

[path stroke];

NSRect drawingOval = [self currentOvalRect];

ovalPath = [NSBezierPath bezierPathWithOvalInRect:drawingOval];

[ovalPath closePath];

[[NSColor redColor] set];

[ovalPath stroke];

if(image)

{

NSRect imageRect;

imageRect.origin = NSZeroPoint;

imageRect.size = [image size];

NSRect drawingRect = [self currentRect];

[image drawInRect:drawingRect fromRect:imageRect operation:NSCompositeSourceOver fraction: opacity];

}


}

文件名:imagefun_upload.zip

文件大小:4 KB

下载地址:http://1000eb.com/8upe
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: