UIImageC处理

1、等比缩放

  1. - (UIImage *) scaleImage:(UIImage *)image toScale:(float)scaleSize {
  2. UIGraphicsBeginImageContext(CGSizeMake(image.size.width * scaleSize, image.size.height * scaleSize);
  3. [image drawInRect:CGRectMake(0, 0, image.size.width * scaleSize, image.size.height * scaleSize)];
  4. UIImage *scaledImage = UIGraphicsGetImageFromCurrentImageContext();
  5. UIGraphicsEndImageContext();
  6. return scaledImage;
  7. }

2、自定义大小

  1. - (UIImage *) reSizeImage:(UIImage *)image toSize:(CGSize)reSize {
  2. UIGraphicsBeginImageContext(CGSizeMake(reSize.width, reSize.height));
  3. [image drawInRect:CGRectMake(0, 0, reSize.width, reSize.height)];
  4. UIImage *reSizeImage = UIGraphicsGetImageFromCurrentImageContext();
  5. UIGraphicsEndImageContext();
  6. return reSizeImage;
  7. }

3、处理某个特定的view

只要是继承UIView的object 都可以处理
     必须先import QuzrtzCore.framework

  1. -(UIImage*) captureView:(UIView *)theView {
  2. CGRect rect = theView.frame;
  3. UIGraphicsBeginImageContext(rect.size);
  4. CGContextRef context = UIGraphicsGetCurrentContext();
  5. [theView.layer renderInContext:context];
  6. UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
  7. UIGraphicsEndImageContext();
  8. return img;
  9. }

4、存储图片

4.1、存储到app的文件里

把要处理的图片以image.png的名字存储到app home地下的Document目录中

  1. NSString *path = [[NSHomeDirectory()stringByAppendingPathComponent:@"Documents"]stringByAppendingPathComponent:@"image.png"];
  2. [UIImagePNGRepresentation(image) writeToFile:pathatomically:YES];

4.2、存储到手机的图片库中

  1. CGImageRef screen = UIGetScreenImage();
  2. UIImage* image = [UIImage imageWithCGImage:screen];
  3. CGImageRelease(screen);
  4. UIImageWriteToSavedPhotosAlbum(image, self, nil, nil);

获取当前app的名称和版本号

  1. NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
  2. // app名称
  3. NSString *name = [infoDictionary objectForKey:@"CFBundleDisplayName"];
  4. // app版本
  5. NSString *version = [infoDictionary objectForKey:@"CFBundleShortVersionString"];
  6. // app build版本
  7. NSString *build = [infoDictionary objectForKey:@"CFBundleVersion"];

UILabel根据text自动调整大小

  1. label.text = @"**********";
  2. CGRect frame = label.frame;
  3. frame.size.height = 10000;  // 设置一个很大的高度
  4. label.frame = frame;
  5. [label sizeToFit];
  6. frame.size.height = label.frame.size.height;
  7. label.frame = frame;

直接拨打有分机号的电话

  1. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://01011112222,3333"]];

参考:http://apluck.iteye.com/blog/1418640#

UIImageC处理的更多相关文章

随机推荐

  1. Git的一些基本概念

    Git的一些基本概念 设置自己的用户名和邮箱git config –global user.name "Your Name"git config –global user.emai ...

  2. Oracle删除表、字段之前判断表、字段是否存在

    这篇文章主要介绍了Oracle删除表.字段之前判断表.字段是否存在的相关资料,需要的朋友可以参考下 在Oracle中若删除一个不存在的表,如 “DROP TABLE tableName”,则会提示: ...

  3. CentOS搭建OpenVPN服务(简易版)

    OpenVPN服务端配置 1. 安装OpenVPN软件包 默认的Centos软件源里面没有OpenVPN的软件包,我们可以添加rpmforge的repo,从而实现yum安装openvpn 针对Cent ...

  4. BZOJ 1682: [Usaco2005 Mar]Out of Hay 干草危机

    Description 牛们干草要用完了!贝茜打算去勘查灾情. 有N(2≤N≤2000)个农场,M(≤M≤10000)条双向道路连接着它们,长度不超过10^9.每一个农场均与农场1连通.贝茜要走遍每一 ...

  5. 常用的python模块

    http://tiankonghaikuo1000.blog.163.com/blog/static/18231597200812424255338/ adodb:我们领导推荐的数据库连接组件bsdd ...

  6. SpringMVC可以配置多个拦截后缀*.html和.do等

    一个servlet可以配置多个servlet-mapping, 因此在xml文件中我们可以这样配置: <!-- springmvc配置 --> <servlet> <se ...

  7. TYPEC 接口芯片CC逻辑原理与必要性

    USB Type-C凭借其自身强大的功能,在Apple,Intel,Google等厂商的强势推动下,必将迅速引发一场USB接口的革命,并将积极影响我们日常生活的方方面面.为了能够使自己的设备兼容这些接 ...

  8. IPv6 tutorial 1 Get started now

    https://4sysops.com/archives/ipv6-part-1-get-started-now/ You’ve probably heard the news that the In ...

  9. 我的第一个Hibernate程序

    1.建表建序列(所用数据库为Oracle,数据库名为XE,创建用户hibernate,密码为123456) conn system/manager; ; grant connect to hibern ...

  10. 结构体dict_table_t

    typedef struct dict_table_struct dict_table_t; /** Data structure for a database table. Most fields ...