ios - renderInContext image drawing with specified size -


how draw smaller image size of context without using cgaffinetransform?

uigraphicsbeginimagecontext(size); cgcontextref context = uigraphicsgetcurrentcontext(); // center image cgcontexttranslatectm(context, placement.origin.x, placement.origin.y); [imageview.layer renderincontext:context]; 

the problem if imageview.image.size bigger size drawn centered, cut @ borders (bigger image drawing area). want image fit, decrease size of imageview.image.size. there way achieve using renderincontext?

via [imageview.layer renderincontext:context]; can't change size (or didn't find way). option so, create image drawimage (on requested size), allocate new uiimageview , draw layer.

uiimage *resizedimage = [self createnewimagefrom:currentimage withsize:size]; uiimageview *imageview = [[uiimageview alloc] initwithimage:resizedimage]; // ... [imageview.layer renderincontext:context];   - (uiimage*)createnewimagefrom:(uiimage*)image withsize:(cgsize)size {     uigraphicsbeginimagecontextwithoptions(size, no, 0.0);     cgcontextref context = uigraphicsgetcurrentcontext();     cgcontexttranslatectm(context, 0.0f, size.height);     cgcontextscalectm(context, 1.0, -1.0);     cgcontextdrawimage(context, cgrectmake(0.0f, 0.0f, size.width, size.height), image.cgimage);     uiimage *outputimage = uigraphicsgetimagefromcurrentimagecontext();     uigraphicsendimagecontext();     return outputimage; } 

Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -