Mac OS Cocoa:在画布上绘制一个简单像素 [英] Mac OS Cocoa: Draw a simple pixel on a canvas

查看:142
本文介绍了Mac OS Cocoa:在画布上绘制一个简单像素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望我能找到答案.我已经搜寻了,找不到正确的答案.这是我的情况:

I wish I would find an answer for this. I have searched and searched and couldn't the right answer. Here is my situation:

在Mac OS Cocoa应用程序中,我想在应用程序窗口的专用区域上绘制一个像素(实际上是几个像素).我认为,最好在其中放置一个NSImageView(我是通过IB这样做的,并将插座连接到我的应用程序代表),然后在其上绘制而不是我的NSWindow.

In a Mac OS Cocoa Application, I want to draw a pixel (actually a few pixels) onto a dedicated area on my application window. I figured, it would be nicer to have a NSImageView placed there (I did so with IB and connected the outlet to my app delegate) and draw on that instead of my NSWindow.

我该怎么做? Mac OS似乎提供NSBezierPath作为最基本的绘图工具—.真的吗?这完全让我震惊.我来自Windows编程的悠久历史,通常将像素绘制到画布上是最简单的事情.

How in the world can I do that? Mac OS seems to offer NSBezierPath as the most basic drawing tool — is that true? This is completely shocking to me. I come from a long history of Windows programming and drawing a pixel onto a canvas is the most simple thing, typically.

我不想使用OpenGL,也不确定Quartz涉及到什么程度.

I do not want to use OpenGL and I am not sure to what extent Quartz is involved in this.

我想要的是一些有关如何在真实的Objective-C/Cocoa中实现此伪代码的帮助:

All I want is some help on how I can pull off this pseudocode in real Objective-C/Cocoa:

imageObj.drawPixel(10,10,blackColor);

我很想听听您对此的回答,并且我相信这会对从可可开始的很多人有所帮助.

I would love to hear your answers on this and I am sure this will help a lot of people starting with Cocoa.

谢谢!

推荐答案

NSBezierPath是Cocoa中唯一可用于绘制大多数原始形状以及许多复杂形状的工具. 详细说明,您可以在这里找到: http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CocoaDrawingGuide/Paths/Paths.html%23//apple_ref/doc/uid/TP40003290-CH206-BBCHFJJG http://en.wikibooks.org/wiki/Programming_Mac_OS_X_with_Cocoa_for_Beginners/Graphics_-_Drawing_with_Quartz

NSBezierPath is the only tool available in Cocoa for drawing most primitive shapes, and for many complex shapes. Detail description you can find here: http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CocoaDrawingGuide/Paths/Paths.html%23//apple_ref/doc/uid/TP40003290-CH206-BBCHFJJG http://en.wikibooks.org/wiki/Programming_Mac_OS_X_with_Cocoa_for_Beginners/Graphics_-_Drawing_with_Quartz

这篇关于Mac OS Cocoa:在画布上绘制一个简单像素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆