Skip to content

Instantly share code, notes, and snippets.

@stigi
Created August 30, 2011 14:47
Show Gist options
  • Select an option

  • Save stigi/1181065 to your computer and use it in GitHub Desktop.

Select an option

Save stigi/1181065 to your computer and use it in GitHub Desktop.
- (UIImage *)optimizedWaveformMask;
{
if (optimizedWaveformMask) return optimizedWaveformMask;
UIImage *originalWaveformImage = track.waveformImage;
if (!originalWaveformImage) return nil;
CGRect maskRect = CGRectZero, imageRect = CGRectZero;
maskRect.size = CGSizeMake(CGRectGetWidth(self.bounds) * [self contentScaleFactor],
CGRectGetHeight(self.bounds) * [self contentScaleFactor]);
imageRect = maskRect;
if (halfWaveform) {
if (self.isFliped == NO) {
imageRect.origin.y -= imageRect.size.height;
}
imageRect.size.height *= 2;
}
UIGraphicsBeginImageContext(maskRect.size);
CGContextRef ctx = UIGraphicsGetCurrentContext();
[originalWaveformImage drawInRect:imageRect];
CGContextSetBlendMode(ctx, kCGBlendModeXOR);
CGContextSetFillColorWithColor(ctx,[UIColor blackColor].CGColor);
CGContextFillRect(ctx, maskRect);
optimizedWaveformMask = [UIGraphicsGetImageFromCurrentImageContext() retain];
UIGraphicsEndImageContext();
return optimizedWaveformMask;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment