티스토리 뷰
NSString * yourImageUrl = [@"URL" stringByAppendingString:yourfile];
NSString * imageName = @"yourImage.png";
NSURL * yourUrl = [NSURL URLWithString:yourImageUrl];
NSData * yourdata = [NSData dataWithContentsOfURL:yourUrl];
UIImage * image = [[UIImage alloc] initWithData:yourdata];
UIImage * scaledImage = [image scaleToSize:CGSizeMake(MYIMAGEWIDTH, MYIMAGEHEIGHT)];
//scaleToSize Method는 따로 정의
NSData * _imageData = [NSData dataWithData:UIImagePNGRepresentation(scaledImage)];
if (![self writeApplicationData:_imageData toFile:imageName]) {
NSLog(@"Save failed!");
}
////
- (BOOL) writeApplicationData:(NSData *)data toFile:(NSString *)fileName
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
if (!documentsDirectory) {
NSLog(@"Documents directory not found!");
return NO;
}
NSString *appFile = [documentsDirectory stringByAppendingPathComponent:fileName];
return ([data writeToFile:appFile atomically:YES]);
}'Object-C,Swift Tip' 카테고리의 다른 글
iOS 개발자 등록에 있어 국내카드로 결제시 인증 실패한 경우 (0) | 2011.09.01 |
---|---|
숫자만 골라내기 (0) | 2011.08.31 |
block 사용 (0) | 2011.08.31 |
키패드 따라 움직이는 textField (0) | 2011.06.25 |
ASIHTTPRequest (0) | 2011.05.13 |