ios - 为什么我的文字没有在视网膜显示器上正确绘制
<p><p>我正在尝试绘制一些文本,它在非视网膜显示器上很好,但在视网膜显示器上它不是高分辨率。</p>
<p>这是我的 iPad Air 的屏幕截图:</p>
<p> <img src="/image/beUeb.png" alt="enter image description here"/> </p>
<p>代码见下文,它实际上将文本绘制成半透明的,周围有一个几乎不透明的蒙版,因此您可以通过文本看到图像。</p>
<pre><code>-(void) maskImage:(UIImageView *)imageView withText:(NSString *)text font:(UIFont *)font attributes:(NSDictionary *)attributes yOffset:(CGFloat)yOffset
{
NSStringDrawingContext *paraContext = [ init];
NSStringDrawingOptions stringDrawingOptions = NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingTruncatesLastVisibleLine;
// find out how much space we need for the text
CGSize textSize = CGSizeIntegral(.size);
// set up the frame for drawing the text, including some padding
CGSize drawingSize = {textSize.width + 80, textSize.height + 60};
CGRect drawingFrame = { 0, 0, drawingSize.width, drawingSize.height};
CGRect textFrame = { 40, 30, textSize.width, textSize.height };
UIGraphicsBeginImageContextWithOptions(drawingSize, YES, 0);
UIColor *bgColor = ;
;
;
UIBezierPath *path = ;
;
// draw the text
;
UIImage *textImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
// now create an image mask from the text image
CIImage *inputImage = ;
CIFilter *filter = ;
CIImage *outputImage = ;
imageView.image = ;
// final set the UIImageView size to match the drawing size
CGRect imageViewFrame = imageView.frame;
imageViewFrame.size = drawingSize;
imageView.frame = imageViewFrame;
}
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>Oliver Jones 帮我解决了这个问题。谢谢@orj!</p>
<p>答案是用</p>创建 UIImage
<pre><code> ;
</code></pre>
<p>而不是</p>
<pre><code> imageView.image = ;
</code></pre>
<p>这会正确设置输出图像的比例。</p></p>
<p style="font-size: 20px;">关于ios - 为什么我的文字没有在视网膜显示器上正确绘制,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/24797815/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/24797815/
</a>
</p>
页:
[1]