NSString drawAtPoint - 模糊 [英] NSString drawAtPoint - blurry

查看:290
本文介绍了NSString drawAtPoint - 模糊的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试在我的应用程序中添加一个NSString到NSImage。由于某种原因,它似乎是非常模糊和嘈杂。这是保存为jpeg的输出。

I have been trying to add an NSString to an NSImage in my application. For some reason it seems to be extremely blurry and noisy. Here is the output that is saved as a jpeg.

http://i.stack.imgur.com/QHVQF.jpg

我读过,这可能是因为绘图一个点不是圆角数字,但它似乎没有改变任何东西。

I have read that it might have been due to drawing it at a point that is not rounded numbers, but it doesn't seem to change anything. I made sure the cords are exactly integers.

以下是我添加文本的方法:

Here is how I add the text:

[generatedRectangle lockFocus];
//Draw according to the settings
[color set];
NSRectFill(NSMakeRect(0, 0, sizeX, sizeY));


NSPoint p = NSMakePoint(round(sizeX/2), round(sizeY/2));

[text drawAtPoint:p withAttributes:NULL];

然后我通过捕获NSBitmapImageRep来保存它,并将其传递到保存面板。
我实际上是用这个命令写的文件:

Then I save it by capturing it with an NSBitmapImageRep and pass it to the save panel. I actually write the file by this command:

[[generatedRect representationUsingType: NSJPEGFileType properties: nil]
   writeToFile:[save filename] atomically: YES])

有关为什么文本如此模糊的任何想法?

Any ideas on why the text is so blurry? I ran out of ideas a good bit ago.

所有的帮助都非常感谢。

All help is greatly appreciated.

推荐答案

请注意,Quartz使用中间像素边界,因此您可能需要确保 -drawAtPoint:withAttributes:坐标不是积分,而是偏移X和Y中的半像素(例如:10.5,10.5而不是10.0,10.0)。

Be aware that Quartz draws on mid-pixel boundaries, so you may need to make sure your -drawAtPoint:withAttributes: coordinate is not integral, but offset by a half pixel in X and Y (for example: 10.5, 10.5 instead of 10.0, 10.0).

此外,确保您的层次结构中的视图全部具有它们在整数像素边界上的起点。即使一个超级视图的文本绘图视图关闭也可能导致模糊的渲染。您可以使用核心动画工具的颜色不对齐图层选项来跟踪这些视图是否支持图层。

Also, make sure that views in your hierarchy being drawn out all have their origins on integral pixel boundaries. Even one superview of your text-drawing view being off can lead to blurry rendering. You may be able to use the Core Animation instrument's Color Misaligned Layers option to track this down, if these views are layer-backed.

这篇关于NSString drawAtPoint - 模糊的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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