iPhone中对UIImage对象处理的常用方法
来源:互联网 发布:朗威dislab软件下载 编辑:程序博客网 时间:2024/04/28 15:06
(一)根据给定得图片,从其指定区域截取一张新得图片
-(UIImage *)getImageFromImage{
//大图bigImage
//定义myImageRect,截图的区域
CGRect myImageRect = CGRectMake(10.0, 10.0, 57.0, 57.0);
UIImage* bigImage= [UIImage imageNamed:@"k00030.jpg"];
CGImageRef imageRef = bigImage.CGImage;
CGImageRef subImageRef = CGImageCreateWithImageInRect(imageRef, myImageRect);
CGSize size;
size.width = 57.0;
size.height = 57.0;
UIGraphicsBeginImageContext(size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextDrawImage(context, myImageRect, subImageRef);
UIImage* smallImage = [UIImage imageWithCGImage:subImageRef];
UIGraphicsEndImageContext();
return smallImage;
}
-(UIImage*)resizedImage1:(UIImage*)inImage inRect:(CGRect)thumbRect {
// Creates a bitmap-based graphics context and makes it the current context.
UIGraphicsBeginImageContext(thumbRect.size);
[inImage drawInRect:thumbRect];
return UIGraphicsGetImageFromCurrentImageContext();
}
-(UIImage*)resizedImage2:(UIImage*)inImage inRect:(CGRect)thumbRect {
CGImageRef imageRef = [inImage CGImage];
CGImageAlphaInfo alphaInfo = CGImageGetAlphaInfo(imageRef);
// There's a wierdness with kCGImageAlphaNone and CGBitmapContextCreate
// see Supported Pixel Formats in the Quartz 2D Programming Guide
// Creating a Bitmap Graphics Context section
// only RGB 8 bit images with alpha of kCGImageAlphaNoneSkipFirst, kCGImageAlphaNoneSkipLast, kCGImageAlphaPremultipliedFirst,
// and kCGImageAlphaPremultipliedLast, with a few other oddball image kinds are supported
// The images on input here are likely to be png or jpeg files
if (alphaInfo == kCGImageAlphaNone)
alphaInfo = kCGImageAlphaNoneSkipLast;
// Build a bitmap context that's the size of the thumbRect
CGFloat bytesPerRow;
if( thumbRect.size.width > thumbRect.size.height ) {
bytesPerRow = 4 * thumbRect.size.width;
} else {
bytesPerRow = 4 * thumbRect.size.height;
}
CGContextRef bitmap = CGBitmapContextCreate(
NULL,
thumbRect.size.width, // width
thumbRect.size.height, // height
8, //CGImageGetBitsPerComponent(imageRef), // really needs to always be 8
bytesPerRow, //4 * thumbRect.size.width, // rowbytes
CGImageGetColorSpace(imageRef),
alphaInfo
);
// Draw into the context, this scales the image
CGContextDrawImage(bitmap, thumbRect, imageRef);
// Get an image from the context and a UIImage
CGImageRef ref = CGBitmapContextCreateImage(bitmap);
UIImage* result = [UIImage imageWithCGImage:ref];
CGContextRelease(bitmap); // ok if NULL
CGImageRelease(ref);
return result;
}
- (UIImage *)scaleImage:(UIImage *) image maxWidth:(float) maxWidth maxHeight:(float) maxHeight
{
CGImageRef imgRef = image.CGImage;
CGFloat width = CGImageGetWidth(imgRef);
CGFloat height = CGImageGetHeight(imgRef);
if (width <= maxWidth && height <= maxHeight)
{
return image;
}
CGAffineTransform transform = CGAffineTransformIdentity;
CGRect bounds = CGRectMake(0, 0, width, height);
if (width > maxWidth || height > maxHeight)
{
CGFloat ratio = width/height;
if (ratio > 1)
{
bounds.size.width = maxWidth;
bounds.size.height = bounds.size.width / ratio;
}
else
{
bounds.size.height = maxHeight;
bounds.size.width = bounds.size.height * ratio;
}
}
CGFloat scaleRatio = bounds.size.width / width;
UIGraphicsBeginImageContext(bounds.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextScaleCTM(context, scaleRatio, -scaleRatio);
CGContextTranslateCTM(context, 0, -height);
CGContextConcatCTM(context, transform);
CGContextDrawImage(UIGraphicsGetCurrentContext(), CGRectMake(0, 0, width, height), imgRef);
UIImage *imageCopy = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return imageCopy;
}
- iPhone中对UIImage对象处理的常用方法
- iphone UIImage常用方法
- IOS中对图片的处理 UIImage
- iPhone图片UIImage对象操作的一些方法
- iPhone中一种对超级大图的显示处理方法
- iOS开发中常用的分类方法---UIImage+extension
- 进阶!Quartz2D对UIImage的常用操作
- Date对象中处理时间和日期的常用方法
- iphone开发中对Icon等的图片的Default处理方法
- iphone开发中对Icon等的图片的Default处理方法
- iphone开发 对UIImage切割
- Python对字符串的常用处理方法
- uiimage常用方法总结
- 数字对象的常用处理方法NSNumber
- 在Javascript中对String的一些方法扩展,实现常用的字符串处理。
- 在Javascript中对Array的一些方法扩展,实现常用的查询处理。
- UITableView中改变UIImage尺寸的方法
- ios中,uiimage拼接图片的方法
- 国产ERP和国外差距到底有多大
- itemRenderer
- Hibernate学习笔记:每个具体的类一张表
- 装了windows后又装了Ubuntu9.04,如何完整卸载Ubuntu9.04
- gethostbyname使用
- iPhone中对UIImage对象处理的常用方法
- 求购视频开源码.
- C#程序在线升级代码
- 是的,我23岁
- C# 3.0 特性预览(2006-5-20 23:57:00)
- wubi 安装Ubuntu
- tomcat 6.0配置
- 黑客书架上出现频率最高的9部半书籍
- 完美国际发包call优化版(delphi)