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
// show image | |
self.imageView.image = [UIImage imageNamed:@"imagename"]; | |
// create effect | |
UIBlurEffect *blur = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]; | |
// add effect to an effect view | |
UIVisualEffectView *effectView = [[UIVisualEffectView alloc]initWithEffect:blur]; | |
effectView.frame = self.view.frame; |
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
// 直接翻转UIImageView | |
func flipImageView(imageView: UIView) { | |
imageView.transform = CGAffineTransform(scaleX: -1, y: 1) | |
} | |
// 修改imageOrientation属性, 这个方法只适用于UIKit中显示的image | |
func flipImage(originImage: UIImage) -> UImage { | |
let cgImage = originImage.cgImage! | |
let flipedImage = UIImage(cgImage: originImage, |
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 *)fixImageOrientation { | |
UIImageOrientation originOrientation = self.imageOrientation; | |
// No-op if the orientation is already correct | |
if (originOrientation == UIImageOrientationUp) return self; | |
// We need to calculate the proper transformation to make the image upright. | |
// We do it in 2 steps: Rotate if Left/Right/Down, and then flip if Mirrored. | |
CGAffineTransform transform = CGAffineTransformIdentity; |
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
func drawPDFfromURL(url: URL) -> UIImage? { | |
guard let document = CGPDFDocument(url as CFURL) else { return nil } | |
guard let page = document.page(at: 1) else { return nil } | |
let pageRect = page.getBoxRect(.mediaBox) | |
let renderer = UIGraphicsImageRenderer(size: pageRect.size) | |
let img = renderer.image { ctx in | |
UIColor.white.set() | |
ctx.fill(pageRect) |
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
import AssetsLibrary | |
import MobileCoreServices | |
/// 保存gif图到相册 | |
func saveGif2Album() { | |
let gifPath = Bundle.main.path(forResource: "name", ofType: "gif") | |
let gifData = NSData(contentsOfFile: gifPath!) as Data | |
let library = ALAssetsLibrary() |
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
// Create a UIImage from sample buffer data | |
- (UIImage *) imageFromSampleBuffer:(CMSampleBufferRef) sampleBuffer { | |
// Get a CMSampleBuffer's Core Video image buffer for the media data | |
CVImageBufferRef imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer); | |
// Lock the base address of the pixel buffer | |
CVPixelBufferLockBaseAddress(imageBuffer, 0); | |
// Get the number of bytes per row for the pixel buffer | |
void *baseAddress = CVPixelBufferGetBaseAddress(imageBuffer); |
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
/** 跳转AppStore app */ | |
- (void)goAppStore:(NSString *)appId { | |
if (!appId || appId.length == 0) { | |
logError(@">> TTAD: AppId不能为空"); | |
return; | |
} | |
logInfo(@">> TTAD: 跳转到内置appstore页: %@", appId); | |
NSString *urlStr = [NSString stringWithFormat:@"https://itunes.apple.com/cn/app/id%@", appId]; | |
NSURL *openURL = [NSURL URLWithString:urlStr]; |
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
/** 跳转AppStore app */ | |
- (void)goAppStore:(NSString *)appId { | |
if (!appId || appId.length == 0) { | |
logError(@">> TTAD: AppId不能为空"); | |
return; | |
} | |
logInfo(@">> TTAD: 跳转到内置appstore页: %@", appId); | |
NSString *urlStr = [NSString stringWithFormat:@"https://itunes.apple.com/cn/app/id%@", appId]; | |
NSURL *openURL = [NSURL URLWithString:urlStr]; |