您的位置:首页 > 移动开发 > IOS开发

ios 图片操作

2012-02-14 17:30 357 查看
http://stackoverflow.com/questions/3837115/display-image-from-url-retrieved-from-alasset-in-iphone   display image from URL retrieved from ALAsset in iPhone

http://stackoverflow.com/questions/1282830/uiimagepickercontroller-uiimage-memory-and-more UIImagePickerController, UIImage, Memory and More? [closed]

/article/1563112.html IPad开发拍照并将图片保存到照片库中

http://stackoverflow.com/questions/1238838/uiimagepickercontroller-and-extracting-exif-data-from-existing-photos UIImagePickerController and extracting EXIF data from existing photos

1.把图片写入文件

- (BOOL)writeImage:(UIImage*)image toFileAtPath:(NSString*)aPath
{
if ((image == nil) || (aPath == nil) || ([aPath isEqualToString:@""]))
return NO;
@try
{
NSData *imageData = nil;

NSString *ext = [aPath pathExtension];

if ([ext isEqualToString:@"png"])
{
imageData = UIImagePNGRepresentation(image);
NSLog(@"png");
}
else
{
NSLog(@"jpg");
// the rest, we write to jpeg
// 0. best, 1. lost. about compress.
imageData = UIImageJPEGRepresentation(image, 0);
}
if ((imageData == nil) || ([imageData length] <= 0))
return NO;
[imageData writeToFile:aPath atomically:YES];
return YES;
}
@catch (NSException *e)
{
NSLog(@"create thumbnail exception.");
}
return NO;
}


2.从文件加载图片

-(UIImage *)loadImageFromFile:(NSString *) aPath;
{
UIImage *im=[[UIImage alloc] initWithContentsOfFile:[self dataFilePath:aPath]];
if (im==nil)
NSLog(@"nil %@",[self dataFilePath:aPath]);
return im;
}


3. uiimage大小

image.size.width,image.size.height


4.点击图片响应事件

resizedImageView.userInteractionEnabled = YES;
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(photoTapped)];
[resizedImageView addGestureRecognizer:singleTap];//点击图片事件
NSLog(@"haha");
[self.view addSubview:resizedImageView];//加载图片
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: