iOS 对UIImage进行的一些操作
生活随笔
收集整理的這篇文章主要介紹了
iOS 对UIImage进行的一些操作
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1、生成指定寬高的UIImage對象(oldImage為原始圖片對象,newImage為操作后的圖片對象)
// 參數1:圖片的尺寸 參數2:是否透明(沒看出YES和NO有什么區別) 參數3:縮放(1表示不縮放) (1) UIGraphicsBeginImageContextWithOptions(CGSize size, BOOL opaque, CGFloat scale) (2) UIGraphicsBeginImageContext(CGSizeMake(newWidth, newHeight)); // 用(1)和(2)都可以
[oldImage drawInRect:CGRectMake(0, 0, newWidth, newHeight)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return newImage;
2、對UIImage進行裁剪
// bounds(NSRect) : 其中x,y 為截取的起始點,width,height 為截取圖片尺寸 CGImageRef imageRef = CGImageCreateWithImageInRect([oldImage CGImage], bounds); UIImage *newImage = [UIImage imageWithCGImage:imageRef];
CGImageRelease(imageRef); return newImage;
?
轉載于:https://www.cnblogs.com/chenyanliang/p/first-.html
總結
以上是生活随笔為你收集整理的iOS 对UIImage进行的一些操作的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 现在纹绣培训学校学费一般多少钱?有参加过
- 下一篇: 2.抽取代码(BaseActivity)