Created
August 30, 2011 14:47
-
-
Save stigi/1181065 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| - (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