设为首页 加入收藏

TOP

iOS 图片的截取
2014-11-24 07:37:41 来源: 作者: 【 】 浏览:1
Tags:iOS 图片 截取

iOS 图片的截取


第一种:整个屏幕截取

在ViewController中写的,这个类是一个视图控制器


-(void)loadView{

//静态方法sharedApplication
[[UIApplication sharedApplication]setStatusBarHidden:YES //把状态栏隐藏
withAnimation:UIStatusBarAnimationSlide];
UIImage *mage=[UIImage imageNamed:@"image.png"];
UIImageView *imageView=[[UIImageView alloc]initWithFrame:[[UIScreen mainScreen]applicationFrame]];

//UIImageView *im=[UIImageView alloc]initWithImage:mage];
[imageView setImage:mage];

self.view=[[UIView alloc]initWithFrame:[[UIScreen mainScreen]applicationFrame]];
[self.view addSubview:contentView];
CGRect rect=CGRectMake(0, 0, 320, 480);
UIGraphicsBeginImageContext(rect.size);
CGContextRef currentContext=UIGraphicsGetCurrentContext();
CGContextClipToRect(currentContext,rect);
CGContextDrawImage(currentContext, rect, mage.CGImage);
UIImage *image=UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
contentView.image=image;
self.view=[[UIView alloc]initWithFrame:[[UIScreen mainScreen]applicationFrame]];
[self.view addSubview:contentView];
[image release];

}


第二种:整张图片的缩略

-(void)loadView{
[[UIApplication sharedApplication]setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
UIImage *image=[UIImage imageNamed:@"image.png"];
//UIImageView *contentView=[[UIImageView alloc]initWithFrame:[[UIScreen mainScreen] applicationFrame]];

//用来控制图片缩到多大
CGRect rect=CGRectMake(0, 0, 160, 240);
UIGraphicsBeginImageContext(rect.size);
CGContextRef currentContent=UIGraphicsGetCurrentContext();
CGContextClipToRect(currentContent, rect);
[image drawInRect:rect];
UIImage *image=UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageView *contentView=[[UIImageView alloc]initWithFrame:rect];
contentView.image=image;
self.view=[[UIView alloc]initWithFrame:[[UIScreen mainScreen]applicationFrame]];
[self.view addSubview:contentView];

[image release];
}


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇Android用PopupWindow实现弹出菜.. 下一篇iOS 截取部分图片并显示

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·PostgreSQL 索引 - (2025-12-25 22:20:43)
·MySQL Node.js 连接 (2025-12-25 22:20:41)
·SQL 撤销索引、表以 (2025-12-25 22:20:38)
·Linux系统简介 (2025-12-25 21:55:25)
·Linux安装MySQL过程 (2025-12-25 21:55:22)