ios - how to make top edge of the waveform rounded -
i want create top edge
, bottom edge
of wave forms in rounded shape .
currently able these wave forms
the code below is
- (uiimage*) drawimagefromsamples:(sint16*)samples maxvalue:(sint16)maxvalue samplecount:(nsinteger)samplecount { cgsize imagesize = cgsizemake(samplecount * (_drawspaces ? 6 : 6), self.height); uigraphicsbeginimagecontextwithoptions(imagesize, no, 0); cgcontextref context = uigraphicsgetcurrentcontext(); cgcontextsetfillcolorwithcolor(context, self.backgroundcolor.cgcolor); cgcontextsetalpha(context, 1.0); cgrect rect; rect.size = imagesize; rect.origin.x = 0; rect.origin.y = 0; cgcolorref wavecolor = self.wavecolor.cgcolor; cgcontextfillrect(context, rect); cgcontextsetlinewidth(context, 2.0); float channelcentery = imagesize.height / 2; float sampleadjustmentfactor = imagesize.height / (float)maxvalue; (nsinteger = 0; < samplecount; i++) { float val = *samples++; val = val * sampleadjustmentfactor; if ((int)val == 0) val = 1.0; // draw dots instead emptyness cgcontextmovetopoint(context, * (_drawspaces ? 6 : 6), channelcentery - val / 2.0); cgcontextaddlinetopoint(context, * (_drawspaces ? 6 : 6), channelcentery + val / 2.0); cgcontextsetstrokecolorwithcolor(context, wavecolor); cgcontextstrokepath(context); } uiimage *newimage = uigraphicsgetimagefromcurrentimagecontext(); uigraphicsendimagecontext(); return newimage; }
try this, cgcontextsetlinecap (context, kcglinecapround);
-(uiimage*) drawimagefromsamples:(sint16*)samples maxvalue:(sint16)maxvalue samplecount:(nsinteger)samplecount { cgsize imagesize = cgsizemake(samplecount * (_drawspaces ? 6 : 6), self.height); uigraphicsbeginimagecontextwithoptions(imagesize, no, 0); cgcontextref context = uigraphicsgetcurrentcontext(); cgcontextsetfillcolorwithcolor(context, self.backgroundcolor.cgcolor); cgcontextsetalpha(context, 1.0); cgrect rect; rect.size = imagesize; rect.origin.x = 0; rect.origin.y = 0; cgcolorref wavecolor = self.wavecolor.cgcolor; cgcontextfillrect(context, rect); cgcontextsetlinewidth(context, 2.0); // start: line added code cgcontextsetlinecap (context, kcglinecapround); // end: line added code float channelcentery = imagesize.height / 2; float sampleadjustmentfactor = imagesize.height / (float)maxvalue; (nsinteger = 0; < samplecount; i++) { float val = *samples++; val = val * sampleadjustmentfactor; if ((int)val == 0) val = 1.0; // draw dots instead emptyness cgcontextmovetopoint(context, * (_drawspaces ? 6 : 6), channelcentery - val / 2.0); cgcontextaddlinetopoint(context, * (_drawspaces ? 6 : 6), channelcentery + val / 2.0);cgcontextsetstrokecolorwithcolor(context, wavecolor); cgcontextstrokepath(context); } uiimage *newimage = uigraphicsgetimagefromcurrentimagecontext(); uigraphicsendimagecontext(); return newimage; }
Comments
Post a Comment