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. js点击图片显示在左边大图

    <div class="imgbox cf">    <img src="temp/pic2.jpg" alt="" cl ...

  2. w3c subscribe

    http://www.w3.org/html/ig/zh/ http://blog.csdn.net/spring21st/article/details/6126537 http://www.w3c ...

  3. Ubuntu下与菜单和图标相关的几个文件夹

    转自UBUNTU下与菜单和图标相关的几个文件夹 /usr/share/icons  系统图标文件夹 /usr/share/applications  系统菜单文件夹,要在左上角的应用程序菜单中添加一项 ...

  4. icon在线编辑和查找工具

    1.www.iconpng.com 2.在线编辑http://www.ico.la/ 3.小图标查找 http://icomoon.io/app/ 4.20个免费的psd http://www.osc ...

  5. 查看linux系统的版本

    1. 查看内核版本命令: 1) [root@SOR_SYS ~]# cat /proc/version Linux version 2.6.18-238.el5 (mockbuild@x86-012. ...

  6. UIcollectionView的使用(首页的搭建4)

    2.5 头部视图

  7. RAM云存储已经出现了,就是特别贵

    据说bat有这种全内存的服务器集群, RAM的问题是,容量上去了就会很费电,而且不方便做持久化,并且成本也不低,一般只能作为缓存.内存数据库,给bat.12306这种高富帅用 也有提供内存云存储的服务 ...

  8. 二维图形的矩阵变换(二)——WPF中的矩阵变换基础

    原文:二维图形的矩阵变换(二)--WPF中的矩阵变换基础 在前文二维图形的矩阵变换(一)——基本概念中已经介绍过二维图像矩阵变换的一些基础知识,本文中主要介绍一下如何在WPF中进行矩阵变换. Matr ...

  9. 【Linux安全】防止任意用户使用 su 切换到 root

    防止任意用户使用 su 切换到 root 在终端中输入下列命令 vim /etc/pam.d/su (按 i 进行编辑,qw 保存并推出) 在头部加入行: auth required pam_whee ...

  10. .Net remoting, Webservice,WCF,Socket区别

    传统上,我们把计算机后台程序(Daemon)提供的功能,称为"服务"(service).比如,让一个杀毒软件在后台运行,它会自动监控系统,那么这种自动监控就是一个"服务& ...