iphone上怎样实现图片裁剪的功能 我现在需要在iphone上实现对一张图片进行裁剪的功能,就是可以选择图片的任何区域进行裁剪,但由于本人对iphone的开发还在初级阶段,希望有大虾帮忙指点一下,谢谢! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 //myImageRect 图片的中一个矩形区域 //image 图片 CGRect myImageRect = CGRectMake(x, y, subWidth, subHeight); CGImageRef imageRef = image.CGImage; CGImageRef subImageRef = CGImageCreateWithImageInRect(imageRef, myImageRect); CGSize size; size.width = subWidth; size.height = subHeight; UIGraphicsBeginImageContext(size); CGContextRef context = UIGraphicsGetCurrentContext(); CGContextDrawImage(context, myImageRect, subImageRef); UIImage* imageCliped = [UIImage imageWithCGImage:subImageRef]; UIGraphicsEndImageContext(); UIGraphicsBeginImageContext(CGSizeMake(IMAGE_SIZE, IMAGE_SIZE)); CGContextRef context=UIGraphicsGetCurrentContext();//获取当前上下文 CGContextTranslateCTM(context, 0.0, image.size.height);//将图片坐标转换成quartz的坐标 CGContextScaleCTM(context, 1.0, -1.0);//将图片坐标转换成quartz的坐标 CGContextDrawImage(context, CGRectMake(-subImageLocationX, i*IMAGE_SIZE, image.size.width, image.size.height), [image CGImage]); //截取图片画在上下文上,注意x轴坐标是负的 UIImage *subImage= UIGraphicsGetImageFromCurrentImageContext();//从上下文上获取图片 UIGraphicsEndImageContext();这样也能实现,而且不会造成不可回收的内存 横屏后 右半边按钮就点不了! 学习ios比较迷茫,请给指条路,谢谢。 UITabBar没有显示出来 程序里的图片加载问题 请教怎么用程序产生shake? 视频播放器前面加载多少秒的广告 xcode 6.0.1 使用模拟器调试异常 code=146 TableView无法点击最后一行 现有ipa文件,需要修改里面的一个域名 GCDAsyncUdpSocket 在应用启动时如何监听UDP包 iPad 开发一个小型的计算器 IPHONE开发环境
//image 图片
CGRect myImageRect = CGRectMake(x, y, subWidth, subHeight);
CGImageRef imageRef = image.CGImage;
CGImageRef subImageRef = CGImageCreateWithImageInRect(imageRef, myImageRect);
CGSize size;
size.width = subWidth;
size.height = subHeight;
UIGraphicsBeginImageContext(size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextDrawImage(context, myImageRect, subImageRef);
UIImage* imageCliped = [UIImage imageWithCGImage:subImageRef];
UIGraphicsEndImageContext();
CGContextRef context=UIGraphicsGetCurrentContext();//获取当前上下文
CGContextTranslateCTM(context, 0.0, image.size.height);//将图片坐标转换成quartz的坐标
CGContextScaleCTM(context, 1.0, -1.0);//将图片坐标转换成quartz的坐标
CGContextDrawImage(context, CGRectMake(-subImageLocationX, i*IMAGE_SIZE, image.size.width, image.size.height), [image CGImage]); //截取图片画在上下文上,注意x轴坐标是负的
UIImage *subImage= UIGraphicsGetImageFromCurrentImageContext();//从上下文上获取图片
UIGraphicsEndImageContext();这样也能实现,而且不会造成不可回收的内存