ios - Why is my image upside down after using CGContextSetFillColorWithColor -
i trying apply color fill mkannotation. found code pretty works reason filled image upside down after applying fill it.
here current code running on map pin.
cgrect rect = cgrectmake(0, 0, self.image.size.width, self.image.size.height); uigraphicsbeginimagecontext(self.image.size); cgcontextref context = uigraphicsgetcurrentcontext(); cgcontextcliptomask(context, rect, self.image.cgimage); cgcontextsetfillcolorwithcolor(context, [[uicolor graycolor] cgcolor]); cgcontextfillrect(context, rect); cgcontextrotatectm(context, 90); uiimage *img = uigraphicsgetimagefromcurrentimagecontext(); uigraphicsendimagecontext(); uiimage *flippedimage = [uiimage imagewithcgimage:img.cgimage scale:1.0 orientation:self.image.imageorientation]; self.image = flippedimage;
here pins after code runs.
i thinking if applied current image orientation flippedimage trick did not work. tried setting self.image = img;
, removing flippedimage var result still same.
cgcontext coordinate system flipped vertically in regard uiview coordinate system. flip this: cgcontexttranslatectm(ctx, 0, imageheight);, cgcontextscalectm(ctx, 1, -1);
Comments
Post a Comment