最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

iOS中常見的視圖和圖片處理示例詳解

 更新時間:2017年10月11日 08:35:32   作者:隨風(fēng)  
在日常ios開發(fā)中經(jīng)常會遇到視圖和圖片的處理,下面這篇文章主要給大家總結(jié)介紹了關(guān)于iOS中常見的視圖和圖片處理的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)和工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下。

前言

眾所周知在開發(fā)中不可避免的會遇到一些圖片和視圖的處理,我這里總結(jié)的這些只是我遇到的一些,以供下次使用查看。下面話不多說了,來一起看看詳細(xì)的介紹吧。

圖片的旋轉(zhuǎn)

是UIImage的擴(kuò)展類,直接使用UIImage的對象調(diào)用即可

UIImage

#import <QuartzCore/QuartzCore.h>
#import <Accelerate/Accelerate.h>
 
@implementation UIImage (ImageRotate)
-(UIImage *)imageRotateIndegree:(float)degree{
 //1.image-》context
 size_t width = (size_t)(self.size.width *self.scale);
 size_t height = (size_t)(self.size.height*self.scale);
 
 size_t bytesPerRow = width * 4;//表明每行圖片數(shù)據(jù)字節(jié)
 CGImageAlphaInfo alphaInfo = kCGImageAlphaPremultipliedFirst;//alpha
 //配置上下文參數(shù)
 CGContextRef bmContext = CGBitmapContextCreate(NULL, width, height, 8, bytesPerRow, CGColorSpaceCreateDeviceRGB(), kCGBitmapByteOrderDefault | alphaInfo);
 if (!bmContext) {
 return nil;
 }
 CGContextDrawImage(bmContext, CGRectMake(0, 0, width, height), self.CGImage);
 //2旋轉(zhuǎn)
 UInt8 *data = (UInt8*)CGBitmapContextGetData(bmContext);
 vImage_Buffer src = {data,height,width,bytesPerRow};
 vImage_Buffer dest = {data,height,width,bytesPerRow};
 Pixel_8888 bgColor = {0,0,0,0};
 vImageRotate_ARGB8888(&src, &dest, NULL, degree, bgColor, kvImageBackgroundColorFill);
 //3context-》UIImage
 CGImageRef rotateImageref = CGBitmapContextCreateImage(bmContext);
 UIImage *rotateImage = [UIImage imageWithCGImage:rotateImageref scale:self.scale orientation:self.imageOrientation];
 return rotateImage;
}
@end

圖片的裁剪

依然是UIImage的擴(kuò)展類,直接使用UIImage的對象調(diào)用即可

UIImage

@implementation UIImage (ImageCut)
 
-(UIImage *)ImageCutSize:(CGRect)rect{
 CGImageRef subImageref = CGImageCreateWithImageInRect(self.CGImage, rect);
 CGRect smallRef = CGRectMake(0, 0, CGImageGetWidth(subImageref), CGImageGetHeight(subImageref));
 
 UIGraphicsBeginImageContext(smallRef.size);
 
 CGContextRef context = UIGraphicsGetCurrentContext();
 CGContextDrawImage(context, smallRef, subImageref);
 UIImage *image = [UIImage imageWithCGImage:subImageref];
 
 UIGraphicsEndImageContext();
 return image;
}
@end

獲取截屏

截屏是UIView的擴(kuò)展類

UIView

@implementation UIView (imageScreenShot)
- (UIImage *)imageScreenShot
{
 UIGraphicsBeginImageContext(self.frame.size);
 [self.layer renderInContext:UIGraphicsGetCurrentContext()];
 UIImage *imageNew = UIGraphicsGetImageFromCurrentImageContext();
 UIGraphicsEndImageContext();
 return imageNew;
}
@end

使用方法

UIView

- (void)imageScreen{
 UIImage *imageNew = [self.view imageScreenShot];
 UIImageWriteToSavedPhotosAlbum(imageNew, nil, nil, nil); //直接保存在相冊里,要獲取相冊權(quán)限
} 

圖片比例處理

依然是UIImage的擴(kuò)展類

UIImage

@implementation UIImage (imageScaleSize)
 
- (UIImage *) scaleImage:(UIImage *)image toScale:(float)scaleSize{
 UIGraphicsBeginImageContext(CGSizeMake(image.size.width * scaleSize, image.size.height * scaleSize));
 [image drawInRect:CGRectMake(0, 0, image.size.width * scaleSize, image.size.height * scaleSize)];
 UIImage *scaledImage = UIGraphicsGetImageFromCurrentImageContext();
 UIGraphicsEndImageContext();
  return scaledImage;
}
@end

view添加圓角

這里是UIView的擴(kuò)展類,適用于所有的View,可以設(shè)置添加的位置

UIView

@implementation UIView (LSCore)
 
/**
 設(shè)置部分圓角 絕對布局
 
 @param corners 需要設(shè)置為圓角的角 UIRectCornerTopLeft|UIRectCornerTopRight
 @param radii 需要設(shè)置的圓角大小 CGSizeMake(5.0, 5.0)
 */
- (void)addRoundedCorners:(UIRectCorner)corners withRadii:(CGSize)radii{
 UIBezierPath *rounded = [UIBezierPath bezierPathWithRoundedRect:self.bounds byRoundingCorners:corners cornerRadii:radii];
 CAShapeLayer *shape = [[CAShapeLayer alloc] init];
 [shape setPath:rounded.CGPath];
 self.layer.mask = shape;
}
 
 
/**
 設(shè)置部分圓角 相對布局
 
 @param corners 需要設(shè)置為圓角的角 UIRectCornerTopLeft|UIRectCornerTopRight
 
 @param radii 需要設(shè)置的圓角大小 CGSizeMake(5.0, 5.0)
 @param rect 需要設(shè)置的圓角view的rect
 */
- (void)addRoundedCorners:(UIRectCorner)corners withRadii:(CGSize)radii viewRect:(CGRect)rect{
 UIBezierPath *rounded = [UIBezierPath bezierPathWithRoundedRect:self.bounds byRoundingCorners:corners cornerRadii:radii];
 CAShapeLayer *shape = [[CAShapeLayer alloc] init];
 [shape setPath:rounded.CGPath];
 self.layer.mask = shape;
}
@end

使用方法以UIImageView為例

UIImage

[image addRoundedCorners:UIRectCornerTopLeft|UIRectCornerTopRight withRadii:CGSizeMake(20.0, 20.0)];

將顏色轉(zhuǎn)為圖片

UIImage

-(UIImage *)ImageForColor:(UIColor *)color{
 CGRect rect = CGRectMake(0.0f, 0.0f, 10, 10);
 UIGraphicsBeginImageContext(rect.size);
 CGContextRef context = UIGraphicsGetCurrentContext();
 
 CGContextSetFillColorWithColor(context, [color CGColor]);
 CGContextFillRect(context, rect);
 
 UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
 UIGraphicsEndImageContext();
 return image;
}

圖片添加系統(tǒng)濾鏡

UIImage

-(UIImage *)blurryImage:(UIImage *)image
   withBlurLevel:(CGFloat)blur {
 CIContext *context = [CIContext contextWithOptions:nil];
 CIImage *inputImage = [CIImage imageWithCGImage:image.CGImage];
 CIFilter *filter = [CIFilter filterWithName:@"CIGaussianBlur"
         keysAndValues:kCIInputImageKey, inputImage,
      @"inputRadius", @(blur),
      nil];
 
 CIImage *outputImage = filter.outputImage;
 CGImageRef outImage = [context createCGImage:outputImage
          fromRect:[outputImage extent]];
 
 return [UIImage imageWithCGImage:outImage];
}

總結(jié)

以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,如果有疑問大家可以留言交流,謝謝大家對腳本之家的支持。

相關(guān)文章

  • iOS捕捉截屏事件并展示截圖效果

    iOS捕捉截屏事件并展示截圖效果

    這篇文章主要為大家詳細(xì)介紹了iOS捕捉截屏事件并展示截圖效果,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2019-01-01
  • iOS應(yīng)用開發(fā)中UITabBarController標(biāo)簽欄控制器使用進(jìn)階

    iOS應(yīng)用開發(fā)中UITabBarController標(biāo)簽欄控制器使用進(jìn)階

    這篇文章主要介紹了iOS應(yīng)用開發(fā)中UITabBarController標(biāo)簽欄控制器的使用進(jìn)階,實(shí)例代碼為傳統(tǒng)的Objective-C,需要的朋友可以參考下
    2016-03-03
  • iOS之加載Gif圖片的方法

    iOS之加載Gif圖片的方法

    本篇文章主要介紹了iOS之加載Gif圖片,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-11-11
  • iOS開發(fā)教程之登錄與訪客的邏輯實(shí)現(xiàn)

    iOS開發(fā)教程之登錄與訪客的邏輯實(shí)現(xiàn)

    這篇文章主要給大家介紹了關(guān)于iOS開發(fā)教程之登錄與訪客的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧。
    2018-04-04
  • iOS點(diǎn)擊查看大圖的動畫效果

    iOS點(diǎn)擊查看大圖的動畫效果

    這篇文章主要為大家詳細(xì)介紹了iOS點(diǎn)擊查看大圖的動畫效果,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-11-11
  • iOS App使用GCD導(dǎo)致的卡頓現(xiàn)象及解決方法

    iOS App使用GCD導(dǎo)致的卡頓現(xiàn)象及解決方法

    這篇文章主要給大家介紹了關(guān)于iOS App使用GCD導(dǎo)致的卡頓現(xiàn)象及解決方法的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2018-07-07
  • IOS開發(fā)基礎(chǔ)之二維數(shù)組詳解

    IOS開發(fā)基礎(chǔ)之二維數(shù)組詳解

    這篇文章主要介紹了IOS開發(fā)基礎(chǔ)之二維數(shù)組詳解的相關(guān)資料,需要的朋友可以參考下
    2017-04-04
  • iOS實(shí)現(xiàn)手勢解鎖操作

    iOS實(shí)現(xiàn)手勢解鎖操作

    這篇文章主要為大家詳細(xì)介紹了iOS實(shí)現(xiàn)手勢解鎖操作功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-03-03
  • IOS實(shí)戰(zhàn)之自定義轉(zhuǎn)場動畫詳解

    IOS實(shí)戰(zhàn)之自定義轉(zhuǎn)場動畫詳解

    這篇文章主要介紹了IOS實(shí)戰(zhàn)之自定義轉(zhuǎn)場動畫,CAAnimation的子類,用于做轉(zhuǎn)場動畫,能夠?yàn)閷犹峁┮瞥銎聊缓鸵迫肫聊坏膭赢嬓Ч?,感興趣的小伙伴們可以參考一下
    2016-02-02
  • IOS開發(fā)中使用writeToFile時的注意事項(xiàng)

    IOS開發(fā)中使用writeToFile時的注意事項(xiàng)

    本篇文章主要介紹了開發(fā)中使用writeToFile時的注意事項(xiàng),具有很好的參考價值。下面跟著小編一起來看下吧
    2017-03-03

最新評論

息烽县| 连山| 惠水县| 广汉市| 泰兴市| 平潭县| 镇远县| 鹿泉市| 常山县| 通许县| 内乡县| 抚宁县| 渭南市| 宁陕县| 金山区| 乌海市| 博客| 淮滨县| 竹山县| 焦作市| 缙云县| 吉安市| 广丰县| 临朐县| 兰坪| 江阴市| 定西市| 万州区| 若羌县| 疏附县| 增城市| 界首市| 威信县| 仙游县| 公安县| 余庆县| 禹城市| 桦甸市| 三河市| 佛冈县| 红安县|