2016-06-29 1 views
0

top edgebottom edgeの波形を丸くして作成します。波形の上端を丸くするには

現在、私は、次のコードは、これを試してみてください

- (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; 

for (NSInteger i = 0; i < sampleCount; i++) 
{ 
    float val = *samples++; 
    val = val * sampleAdjustmentFactor; 
    if ((int)val == 0) 
     val = 1.0; // draw dots instead emptyness 
    CGContextMoveToPoint(context, i * (_drawSpaces ? 6 : 6), channelCenterY - val/2.0); 
    CGContextAddLineToPoint(context, i * (_drawSpaces ? 6 : 6), channelCenterY + val/2.0); 
    CGContextSetStrokeColorWithColor(context, waveColor); 
    CGContextStrokePath(context); 
} 

UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext(); 

UIGraphicsEndImageContext(); 

return newImage; 
} 

答えて

0

あるこれらwave forms

enter image description here

を取得することができています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 to the code 
     CGContextSetLineCap (context, kCGLineCapRound); 
     // End: Line Added to the code 
    float channelCenterY = imageSize.height/2; float sampleAdjustmentFactor = imageSize.height/(float)maxValue; 

    for (NSInteger i = 0; i < sampleCount; i++) { float val = *samples++; val = val * sampleAdjustmentFactor; if ((int)val == 0) val = 1.0; // draw dots instead emptyness 

     CGContextMoveToPoint(context, i * (_drawSpaces ? 6 : 6), channelCenterY - val/2.0); 
     CGContextAddLineToPoint(context, i * (_drawSpaces ? 6 : 6), channelCenterY + val/2.0);CGContextSetStrokeColorWithColor(context, waveColor); CGContextStrokePath(context); } 

     UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext(); 

     UIGraphicsEndImageContext(); 

     return newImage; 
    } 
関連する問題