objective c - Low pixel density when rotation UIImage -


i have found couple algorithm our application rotate annotations on mkmapview, , in every algorithm pixel density of image crashing. here example, green arrow annotation: green arrow annotation example

algorithm

maybe knows algorithm or extension perform correct rotation of image?

rather uigraphicsbeginimagecontext, use uigraphicsbeginimagecontextwithoptions 0 last parameter. maximize screen resolution match device's screen (e.g. retina).


even when create retina resolution image, when rotate bitmap, you're going introducing further pixelation. may sharper results if draw (e.g. in drawrect of annotation view's subclass):

@interface customuserannotationview : mkannotationview  @property (nonatomic) cgfloat angle; @property (nonatomic) cgfloat linewidth; @property (nonatomic, strong) uicolor *strokecolor; @property (nonatomic, strong) uicolor *fillcolor;  @end  @implementation customuserannotationview  - (instancetype)initwithannotation:(id<mkannotation>)annotation reuseidentifier:(nsstring *)reuseidentifier {     self = [super initwithannotation:annotation reuseidentifier:reuseidentifier];      if (self) {         self.linewidth = 2;         self.strokecolor = [uicolor lightgraycolor];         self.fillcolor = [uicolor greencolor];         self.backgroundcolor = [uicolor clearcolor];         self.frame = cgrectmake(0, 0, 50, 50);                 }      return self; }  // should `setneedsdisplay` on other properties' setters, too, i'm assuming angle 1 we're worried right now.  - (void)setangle:(cgfloat)angle {     _angle = angle;     [self setneedsdisplay]; }  - (void)drawrect:(cgrect)rect {     cgpoint center = cgpointmake(self.bounds.size.width / 2.0, self.bounds.size.height / 2.0);     cgfloat radius = (min(self.bounds.size.width, self.bounds.size.height) - self.linewidth) / 2.0;      uibezierpath *path = [uibezierpath bezierpath];     [path movetopoint:   [self pointatradius:radius       percentangle:0.0 center:center angleoffset:self.angle]];     [path addlinetopoint:[self pointatradius:radius       percentangle:0.4 center:center angleoffset:self.angle]];     [path addlinetopoint:[self pointatradius:radius * 0.6 percentangle:0.5 center:center angleoffset:self.angle]];     [path addlinetopoint:[self pointatradius:radius       percentangle:0.6 center:center angleoffset:self.angle]];     [path closepath];     path.linewidth = self.linewidth;     path.linejoinstyle = kcglinejoinround;      [self.fillcolor setfill];     [path fill];      [self.strokecolor setstroke];     [path stroke]; }  - (cgpoint)pointatradius:(cgfloat)radius percentangle:(cgfloat)percentangle center:(cgpoint)center angleoffset:(cgfloat)angleoffset {     cgfloat angle = m_pi * 2.0 * percentangle + angleoffset;     return cgpointmake(center.x + radius * sin(angle), center.y - radius * cos(angle)); }  @end 

enter image description here


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -