将颜色转换为图像?
我不知道我应该如何处理它,但是如果我(在我的 mac 应用程序中)有一个 NSView 网格,用户可以更改每个网格的颜色,是否可以翻译它,所以现在我已经用户给每个像素指定颜色,将其制作成可导出的图像?
老实说,我想不出还有什么办法可以做到这一点。我不想继续前进,意识到我走了一条相当愚蠢的道路。
我的想法是我将有一个用户可以绘制的正方形网格,每个正方形都有一种颜色,一个正方形代表最终图像中的一个像素。因此,他们就像用油漆桶填充每个油漆桶一样进行绘画,然后将其导出到实际的图像文件中。
非常感谢任何帮助,谢谢。
Im not sure how else I should approach it, but if I was to (in my mac application) have a grid of NSViews, which the user can change the colour of each, is it possible to then translate this, so now I have been given a colour for each pixel by the user, make this into an exportable image?
I honestly can't think of how else to do this. I don't want to go ahead an realise I have taken a rather foolish path.
The idea is I will have a grid of squares which the user can paint, a colour in each square, a square representing a pixel in the final image. So they paint with like a paint bucket filling each one, then export it into an actual image file.
Any help much appreciated, thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于您正在做的事情来说,
NSViews
网格听起来确实很重。为什么不编写一个自定义视图来检查鼠标位置并适当地修改数据呢?然后,您可以编写一个自定义绘图方法来填充自定义视图,并且可以使用完全相同的绘图方法来写入可以导出的NSImage
。你需要做一些数学计算。对于每个“像素”,在相应的
NSColor
上调用-set
,然后使用NSBezierPath
的-fillRect
方法。它可能会帮助您拿出铅笔和铅笔。论文计算出直方图原点和直方图的数学公式尺寸。检查 http://developer.apple.com如果您从未做过自定义绘图,请 /library/mac/#documentation/Cocoa/Conceptual/CocoaDrawingGuide/Introduction/Introduction.html 寻求帮助 前。其实没那么糟糕,只是需要一点点阅读。 :)
A grid of
NSViews
sounds really heavy for what you're doing. Why not write one single custom view that checks the mouse position and modifies the data appropriately? Then you'd write a custom drawing method to fill the custom view, and you could use the same exact draw method to write to anNSImage
which you could export.You'll need to do a bit o' math. For each "pixel", call
-set
on the appropriateNSColor
, then useNSBezierPath
's-fillRect
method. It may help you to get out a pencil & paper to figure out the math for the rect origins & sizes.Check http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CocoaDrawingGuide/Introduction/Introduction.html for help if you've never done custom drawing before. It's really not that bad, just takes a little reading. :)