objective c - iOS : Repositioning UIGraphicsBeginImageContext and UIImageView -
i've got code allows me draw on top of uiimageview - want able limit drawing area.
i've been able limit size, i'm unable position it: if change (0, 0) else image disappeared , ability draw stops working
drawimage - uiimageview
- (void)touchesmoved:(nsset *)touches withevent:(uievent *)event { mouseswiped = yes; uitouch *touch = [touches anyobject]; currentpoint = [touch locationinview:self]; uigraphicsbeginimagecontext(cgsizemake(560, 660)); [drawimage.image drawinrect:cgrectmake(0, 0, 560, 660)]; cgcontextsetlinecap(uigraphicsgetcurrentcontext(), kcglinecapround); cgcontextsetlinewidth(uigraphicsgetcurrentcontext(), 5.0); cgcontextsetrgbstrokecolor(uigraphicsgetcurrentcontext(), 0, 1, 0, 1); cgcontextbeginpath(uigraphicsgetcurrentcontext()); cgcontextmovetopoint(uigraphicsgetcurrentcontext(), lastpoint.x, lastpoint.y); cgcontextaddlinetopoint(uigraphicsgetcurrentcontext(), currentpoint.x, currentpoint.y); cgcontextstrokepath(uigraphicsgetcurrentcontext()); [drawimage setframe:cgrectmake(0, 0, 560, 660)]; drawimage.image = uigraphicsgetimagefromcurrentimagecontext(); uigraphicsendimagecontext(); lastpoint = currentpoint; [self addsubview:drawimage]; }
any appreciated
i'm not sure understand you're trying do, i'll take swing:
[drawimage.image drawinrect:cgrectmake(0, 0, 560, 660)];
this tells image assigned drawimage
draw in current context @ 0,0
. since context bitmap image context, extent 0,0
560,660
. seems me want do, otherwise have blank areas in bitmap. if change 0,0
10,0
, expect there 10pt wide blank area in resulting bitmap (which seems waste).
then later this:
[drawimage setframe:cgrectmake(0, 0, 560, 660)];
this setting uiimageview's coordinates in superview's coordinate system. if change that 0,0
to, say, 5,5
expect uiimageview appear 5pt down , 5pt right in superview.
you want "limit drawing area." assume mean part you're drawing on image. easiest way set clip rect on bitmap context before draw. instance, if wanted prevent drawing in 10pt band around edge of image, this:
uigraphicsbeginimagecontext(cgsizemake(560, 660)); [drawimage.image drawinrect:cgrectmake(0, 0, 560, 660)]; cgcontextcliptorect(uigraphicsgetcurrentcontext(), cgrectmake(10,10,540,640)); cgcontextsetlinecap(uigraphicsgetcurrentcontext(), kcglinecapround); // ... , on
not 100% sure if that's you're looking for, helps.
Comments
Post a Comment