iOS 앱을 만들고 UIImage가 있습니다.이 파일을 .png 파일로 압축하여 앱의 문서 폴더에 저장하고 싶습니다. 이미 경로가 있고 필요한 것은 UIImage를 .png로 변환하고 저장하는 것입니다.Xcode iOS .png 파일을 생성하고 NSFileManager를 사용하여 저장합니다.
감사합니다. Matan.
UIImageJPEGRepresentation
데이터를 반환 PNG를 들어
iOS 앱을 만들고 UIImage가 있습니다.이 파일을 .png 파일로 압축하여 앱의 문서 폴더에 저장하고 싶습니다. 이미 경로가 있고 필요한 것은 UIImage를 .png로 변환하고 저장하는 것입니다.Xcode iOS .png 파일을 생성하고 NSFileManager를 사용하여 저장합니다.
감사합니다. Matan.
UIImageJPEGRepresentation
데이터를 반환 PNG를 들어
그래서 코드는 다음과 같습니다
UIImage *yourImage = ...; //the image you have
NSString *targetPath = ...; // something like ~/Library/Documents/myImage.png
[UIImagePNGRepresentation(yourImage) writeToFile:targetPath atomically:YES];
: 대신 JPEG를 원한다면
UIImagePNGRepresentation
은 PNG 형식
NSData * UIImagePNGRepresentation (
UIImage *image
);
에 지정된 이미지에 대한 데이터를 반환 지정된 이미지 JPEG 형식.
NSData * UIImageJPEGRepresentation (
UIImage *image,
CGFloat compressionQuality
);
이미지 압축 형태는
// for getting png image
NSData*theImageData=UIImagePNGRepresentation(theImage);
// for JPG compression change fill value between less than 1
NSData*theImageData=UIImageJPEGRepresentation(theImage, 1);
// for converting raw data image to UIImage
UIImage *imageOrignal=[UIImage imageWithData:theImageData];
// for saving in to photos gallery
UIImageWriteToSavedPhotosAlbum(imageOrignal,nil,nil,nil);
이 아주 아주 감사 JPG 이미지의 다른 품질을 사용하여 JPEG입니다! 완벽하게 작동합니다! – Matan
거기에 png 압축하는 방법은 무엇입니까? –
번호. 당신은 pngcrush 소스를 포함시킬 수 있습니다. 프레임 워크에는 아무것도 없다. –