cocoa touch - How do I draw into a bitmap without antialiasing/interpolation in iOS? -
i'm trying programmatically draw uiimage so:
- (void)viewdidload { [super viewdidload]; // additional setup after loading view, typically nib. uigraphicsbeginimagecontextwithoptions(cgsizemake(2, 2), yes, 1); cgcontextref context = uigraphicsgetcurrentcontext(); // these 3 lines of code apparently nothing. cgcontextsetinterpolationquality(context, kcginterpolationnone); cgcontextsetallowsantialiasing(context, false); cgcontextsetshouldantialias(context, false); cgcontextsetfillcolorwithcolor(context, [uicolor colorwithred:1 green:0 blue:0 alpha:1].cgcolor); cgcontextfillrect(context, cgrectmake(0, 0, 1, 1)); self.imageview.image = uigraphicsgetimagefromcurrentimagecontext(); uigraphicsendimagecontext(); }
this code works except resulting image soft, aggressive attempt @ antialiasing/interpolation. need image scaled using nearest neighbour interpolation. how prevent antialiasing?
thank you!
while image draw context doesn't use anti-aliasing (even though doesn't make difference particular image you're drawing), still default interpolation behavior image view.
to change that, adjust magnificationfilter
/minificationfilter
properties of view's layer:
self.imageview.layer.magnificationfilter = kcafilternearest; self.imageview.layer.minificationfilter = kcafilternearest;
(you need add quartzcore framework work.)
Comments
Post a Comment