Sunday, 15 April 2012

ios - UIImage orientation is changing when drawing in UIGraphicsBeginImageContext -



ios - UIImage orientation is changing when drawing in UIGraphicsBeginImageContext -

i want draw lines on uiimage. able draw lines in context , @ end drawing background image before getting image context below code:

uigraphicsbeginimagecontext(self.bounds.size); cgrect newframe = self.frame; newframe.origin.y = 0; [self.backgroundimage drawinrect:newframe]; [self.layer renderincontext:uigraphicsgetcurrentcontext()]; uiimage *saveimage = uigraphicsgetimagefromcurrentimagecontext(); uigraphicsendimagecontext();

problem is: self.backgroundimage.imageorientation 3 saveimage.imageorientation 0. how can same imageorientation saveimage?

uiimage->drawinrect honor image orientation, after call, result "upright", hence saveimage should have imageorientationup.

if want alter orientation metadata without affecting image, can utilize following:

// recreate uiimage new orientation - (uiimage *) imagewithorientation:(uiimageorientation)value { if (self.imageorientation == value) homecoming self; if (self.cgimage != nil) homecoming [uiimage imagewithcgimage:self.cgimage scale:self.scale orientation:value]; if (self.ciimage != nil) homecoming [uiimage imagewithciimage:self.ciimage scale:self.scale orientation:value]; homecoming nil; }

ios objective-c uiimage

No comments:

Post a Comment