UI_UIImage
2016-07-13 17:13
337 查看
//
// ViewController.m
// UIImage
//
// Created by HarrySun on 16/7/11.
// Copyright © 2016年 Mobby. All rights reserved.
//
#import "ViewController.h"
@interface
ViewController ()
@property (nonatomic,
strong) UIImage *myImage;
@end
@implementation ViewController
- (void)viewDidLoad {
[super
viewDidLoad];
// 使用文件创建
// _myImage = [UIImage imageNamed:@"1"];
// 使用URL创建
// _myImage = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://www.kutx.cn/xiaotupian/icons/png/200803/20080327095245737.png"]]];
// // 通过文件加载指定路径下的文件内容获得新图片
// _myImage = [[UIImage alloc]initWithContentsOfFile:[NSString stringWithFormat:@"%@/Documents/ppp.png",NSHomeDirectory()]];
_myImage = [UIImage
imageWithCGImage:[UIImage
imageNamed:@"1"].CGImage
scale:1
orientation:(UIImageOrientationLeft)];
// 创建的时候指定方法倍数以及旋转方向,scale是倍数,1代表和原图像尺寸一样,orientation
图片方向
// _myImage = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://www.kutx.cn/xiaotupian/icons/png/200803/20080327095245737.png"]]];
// CGImageRef cif=[_myImage CGImage];
// _myImage = [UIImage imageWithCGImage:cif]; //使用Quartz 2D对象创建UIImage
// 使用Core Graphics (静态方法)
// UIImage* myImage3 = [UIImage imageWithCGImage:cif];
UIImageView *imageView = [[UIImageView
alloc] initWithFrame:CGRectMake(50,
100, 100,
100)];
[self.view
addSubview:imageView];
imageView.image =
_myImage;
NSLog(@"%ld",(long)_myImage.imageOrientation);
// 图片方向
NSLog(@"%f,%f",_myImage.size.width,_myImage.size.height);
// 图片大小
NSLog(@"%f",_myImage.scale);
// 图片的比例
// 根据给定的图片,从其指定区域截取一张新的图片
UIImage *image1 = [self
getImageFromImage];
UIImageView *imageView2 = [[UIImageView
alloc] initWithFrame:CGRectMake(50,
250, 100,
100)];
imageView2.backgroundColor = [UIColor
redColor];
[self.view
addSubview:imageView2];
imageView2.image = image1;
UIImage *image3 = [_myImage
imageWithAlignmentRectInsets:(UIEdgeInsetsMake(50,
100,
100, 100))];
// 返回指定矩形区域内的图像
UIImageView *imageView3 = [[UIImageView
alloc] initWithFrame:CGRectMake(50,
400, 100,
100)];
imageView3.image = image3;
[self.view
addSubview:imageView3];
// ?
// UIImage *image4 = [UIImage animatedImageNamed:@"xian-1.png" duration:5];
//
// UIImageView *imageView4 = [[UIImageView alloc] initWithFrame:CGRectMake(200, 100, 100, 100)];
// imageView4.image = image4;
// [self.view addSubview:imageView4];
// --------- 下方设置动画 ---------
NSMutableArray *imageArray = [[NSMutableArray
alloc]
initWithCapacity:30];
for (int i =
1; i < 31; i ++) {
UIImage *aImage = [UIImage
imageNamed:[NSString
stringWithFormat:@"xian-%d",i]];
[imageArray addObject:aImage];
}
UIImage *image = [UIImage
animatedImageWithImages:imageArray
duration:2];
// 用一组图片创建一个动态图片
UIImageView *imgeView5 = [[UIImageView
alloc] initWithFrame:CGRectMake(50,
550, 100,
100)];
imgeView5.image = image;
[self.view
addSubview:imgeView5];
UIImage *image6 = [UIImage
animatedResizableImageNamed:@"1.png"
capInsets:UIEdgeInsetsMake(50,
200,
100, 100)
resizingMode:UIImageResizingModeTile
duration:0];
UIImageView *imageView6 = [[UIImageView
alloc] initWithFrame:CGRectMake(200,
250, 100,
100)];
imageView6.image = image6;
[self.view
addSubview:imageView6];
}
// 根据给定的图片,从其指定区域截取一张新的图片
-(UIImage *)getImageFromImage{
//大图bigImage
//定义myImageRect,截图的区域
CGRect myImageRect =
CGRectMake(50.0,
100.0, 50.0,
50.0);
UIImage* bigImage= [UIImage
imageNamed:@"1.png"];
CGImageRef imageRef = bigImage.CGImage;
CGImageRef subImageRef =
CGImageCreateWithImageInRect(imageRef, myImageRect);
CGSize size;
size.width =
50.0;
size.height =
50.0;
UIGraphicsBeginImageContext(size);
CGContextRef context =
UIGraphicsGetCurrentContext();
CGContextDrawImage(context, myImageRect, subImageRef);
UIImage* smallImage = [UIImage
imageWithCGImage:subImageRef];
UIGraphicsEndImageContext();
return smallImage;
}
- (void)didReceiveMemoryWarning {
[super
didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
// ViewController.m
// UIImage
//
// Created by HarrySun on 16/7/11.
// Copyright © 2016年 Mobby. All rights reserved.
//
#import "ViewController.h"
@interface
ViewController ()
@property (nonatomic,
strong) UIImage *myImage;
@end
@implementation ViewController
- (void)viewDidLoad {
[super
viewDidLoad];
// 使用文件创建
// _myImage = [UIImage imageNamed:@"1"];
// 使用URL创建
// _myImage = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://www.kutx.cn/xiaotupian/icons/png/200803/20080327095245737.png"]]];
// // 通过文件加载指定路径下的文件内容获得新图片
// _myImage = [[UIImage alloc]initWithContentsOfFile:[NSString stringWithFormat:@"%@/Documents/ppp.png",NSHomeDirectory()]];
_myImage = [UIImage
imageWithCGImage:[UIImage
imageNamed:@"1"].CGImage
scale:1
orientation:(UIImageOrientationLeft)];
// 创建的时候指定方法倍数以及旋转方向,scale是倍数,1代表和原图像尺寸一样,orientation
图片方向
// _myImage = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://www.kutx.cn/xiaotupian/icons/png/200803/20080327095245737.png"]]];
// CGImageRef cif=[_myImage CGImage];
// _myImage = [UIImage imageWithCGImage:cif]; //使用Quartz 2D对象创建UIImage
// 使用Core Graphics (静态方法)
// UIImage* myImage3 = [UIImage imageWithCGImage:cif];
UIImageView *imageView = [[UIImageView
alloc] initWithFrame:CGRectMake(50,
100, 100,
100)];
[self.view
addSubview:imageView];
imageView.image =
_myImage;
NSLog(@"%ld",(long)_myImage.imageOrientation);
// 图片方向
NSLog(@"%f,%f",_myImage.size.width,_myImage.size.height);
// 图片大小
NSLog(@"%f",_myImage.scale);
// 图片的比例
// 根据给定的图片,从其指定区域截取一张新的图片
UIImage *image1 = [self
getImageFromImage];
UIImageView *imageView2 = [[UIImageView
alloc] initWithFrame:CGRectMake(50,
250, 100,
100)];
imageView2.backgroundColor = [UIColor
redColor];
[self.view
addSubview:imageView2];
imageView2.image = image1;
UIImage *image3 = [_myImage
imageWithAlignmentRectInsets:(UIEdgeInsetsMake(50,
100,
100, 100))];
// 返回指定矩形区域内的图像
UIImageView *imageView3 = [[UIImageView
alloc] initWithFrame:CGRectMake(50,
400, 100,
100)];
imageView3.image = image3;
[self.view
addSubview:imageView3];
// ?
// UIImage *image4 = [UIImage animatedImageNamed:@"xian-1.png" duration:5];
//
// UIImageView *imageView4 = [[UIImageView alloc] initWithFrame:CGRectMake(200, 100, 100, 100)];
// imageView4.image = image4;
// [self.view addSubview:imageView4];
// --------- 下方设置动画 ---------
NSMutableArray *imageArray = [[NSMutableArray
alloc]
initWithCapacity:30];
for (int i =
1; i < 31; i ++) {
UIImage *aImage = [UIImage
imageNamed:[NSString
stringWithFormat:@"xian-%d",i]];
[imageArray addObject:aImage];
}
UIImage *image = [UIImage
animatedImageWithImages:imageArray
duration:2];
// 用一组图片创建一个动态图片
UIImageView *imgeView5 = [[UIImageView
alloc] initWithFrame:CGRectMake(50,
550, 100,
100)];
imgeView5.image = image;
[self.view
addSubview:imgeView5];
UIImage *image6 = [UIImage
animatedResizableImageNamed:@"1.png"
capInsets:UIEdgeInsetsMake(50,
200,
100, 100)
resizingMode:UIImageResizingModeTile
duration:0];
UIImageView *imageView6 = [[UIImageView
alloc] initWithFrame:CGRectMake(200,
250, 100,
100)];
imageView6.image = image6;
[self.view
addSubview:imageView6];
}
// 根据给定的图片,从其指定区域截取一张新的图片
-(UIImage *)getImageFromImage{
//大图bigImage
//定义myImageRect,截图的区域
CGRect myImageRect =
CGRectMake(50.0,
100.0, 50.0,
50.0);
UIImage* bigImage= [UIImage
imageNamed:@"1.png"];
CGImageRef imageRef = bigImage.CGImage;
CGImageRef subImageRef =
CGImageCreateWithImageInRect(imageRef, myImageRect);
CGSize size;
size.width =
50.0;
size.height =
50.0;
UIGraphicsBeginImageContext(size);
CGContextRef context =
UIGraphicsGetCurrentContext();
CGContextDrawImage(context, myImageRect, subImageRef);
UIImage* smallImage = [UIImage
imageWithCGImage:subImageRef];
UIGraphicsEndImageContext();
return smallImage;
}
- (void)didReceiveMemoryWarning {
[super
didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
相关文章推荐
- GUI - Web前端开发框架
- 评价ui设计作品好坏的八个标准(界面/交互设计研究)
- Jquery ui datepicker设置日期范围,如只能隔3天【实现代码】
- 为Yahoo! UI Extensions Grid增加内置的可编辑器
- Cocos2d-x UI开发之文本类使用实例
- 谈谈对jquery ui tabs 的理解
- 在IE 浏览器中使用 jquery的fadeIn() 效果 英文字符字体加粗
- UI Events 用户界面事件
- 基于Bootstrap的UI扩展 StyleBootstrap
- jQuery UI结合Ajax创建可定制的Web界面
- jquery UI Datepicker时间控件的使用方法(基础版)
- Hallo.js基于jQuery UI所见即所得的Web编辑器
- 基于jQuery UI CSS Framework开发Widget的经验
- jquery ui 1.7 ui.tabs 动态添加与关闭(按钮关闭+双击关闭)
- jquery UI Datepicker时间控件的使用及问题解决
- jQuery UI设置固定日期选择特效代码分享
- Jquery ajax 同步阻塞引起的UI线程阻塞问题
- jQuery UI的Dialog无法提交问题的解决方法
- jQuery ui实现动感的圆角渐变网站导航菜单效果代码
- jquery UI Datepicker时间控件的使用方法(终结版)