作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用自定义栏按钮图像。我创建了一个带有白色对象和透明背景的简单 PNG 图像 recommended by Apple :
如您所见,没有应用抗锯齿(这是我的精确图像,一个像素一个像素)。
Apple 确实推荐使用抗锯齿,但没有提供更多细节。我原以为这将是软件的一个功能,就像处理文本一样,而不是将其预先应用到图像上。
问题是——如何以编程方式为我的自定义栏按钮图像提供抗锯齿功能?
我尝试了几件事,但没有任何效果。这是我尝试过的一件事:
- (UIImage *)antialiasedImage
{
// Check to see if Antialiased Image has already been initialized
if (_antialiasedImage != nil) {
return _antialiasedImage;
}
// Get Device Scale
CGFloat scale = [[UIScreen mainScreen] scale];
// Get the Image from Resource
UIImage *buttonImage = [UIImage imageNamed:@"ReferenceFieldIcon"]; // .png???
// Get the CGImage from UIImage
CGImageRef imageRef = [buttonImage CGImage];
// Find width and height
NSUInteger width = CGImageGetWidth(imageRef);
NSUInteger height = CGImageGetHeight(imageRef);
// Begin Context
UIGraphicsBeginImageContextWithOptions(buttonImage.size, YES, 0);
CGContextRef context = UIGraphicsGetCurrentContext();
// Set Antialiasing Parameters
CGContextSetAllowsAntialiasing(context, YES);
CGContextSetShouldAntialias(context, YES);
CGContextSetInterpolationQuality(context, kCGInterpolationHigh);
// Draw Image Ref on Context
CGContextDrawImage(context, CGRectMake(0, 0, width, height), imageRef);
// End Context
UIGraphicsEndImageContext();
// Set CGImage to UIImage
_antialiasedImage =
[UIImage imageWithCGImage:imageRef scale:scale orientation:UIImageOrientationUp];
// Release Image Ref
CGImageRelease(imageRef);
return _antialiasedImage;
}
然后我像这样创建分段控件:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
NSArray *centerItemsArray =
[NSArray arrayWithObjects: @"S",
self.antialiasedImage,
@"D",
nil];
UISegmentedControl *centerSegCtrl =
[[UISegmentedControl alloc] initWithItems:centerItemsArray];
centerSegCtrl.segmentedControlStyle = UISegmentedControlStyleBar;
UIBarButtonItem *centerButtonItem =
[[UIBarButtonItem alloc] initWithCustomView:(UIView *)centerSegCtrl];
UIBarButtonItem *flexibleSpace =
[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
target:nil
action:nil];
NSArray *barArray = [NSArray arrayWithObjects: flexibleSpace,
centerButtonItem,
flexibleSpace,
nil];
[self setToolbarItems:barArray];
}
提前致谢!
最佳答案
IOS 不会为呈现的图像添加抗锯齿功能——只有从代码中提取的项目。在保存到文件之前,您必须消除图像的锯齿。
从代码中消除图像锯齿的方法是在代码中绘制它们。
关于ios - iOS 中的抗锯齿自定义栏按钮图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17635480/
尝试使用 tkinter 为一系列 PIL 图像制作动画。我的帧持续时间 (ms) 的图表如下所示: 有人知道是什么导致了这种尖尖的锯齿图案吗? 这是一个重现的脚本: from PIL import
我正在尝试使用 Canvas 创建“星爆”效果,但线段出现令人难以置信的像素化。我做错了什么吗? var rays = 40; var canvas = $("header canvas")[0];
爪牙 我在 JAGS 中有一个仅拦截逻辑模型,定义如下: model{ for(i in 1:Ny){ y[i] ~ dbern(mu[s[i]]) } for(j in 1:Ns){
我是一名优秀的程序员,十分优秀!