업로드하기 전에 가능한 한 내 이미지 파일 크기를 줄이려고합니다. 지금이 작업을하고 있습니다.업로드하기 전에 이미지 크기를 줄이십시오.
카메라 나 사진 앨범에서 가져온 이미지를 jpg로 만들어 크기를 줄입니다.
내가 0.1에 설정을 설정 한하지만 크기가 여전히 300~350킬로바이트 주위에 결국 내 이미지를 업로드 할 때, 내가 더 크기를 조정할 수있는 방법이, 나는 50~70킬로바이트
업로드하기 전에 가능한 한 내 이미지 파일 크기를 줄이려고합니다. 지금이 작업을하고 있습니다.업로드하기 전에 이미지 크기를 줄이십시오.
카메라 나 사진 앨범에서 가져온 이미지를 jpg로 만들어 크기를 줄입니다.
내가 0.1에 설정을 설정 한하지만 크기가 여전히 300~350킬로바이트 주위에 결국 내 이미지를 업로드 할 때, 내가 더 크기를 조정할 수있는 방법이, 나는 50~70킬로바이트
당신은
를 호출 % 이상extension UIImage {
func resizeWithPercent(percentage: CGFloat) -> UIImage? {
let imageView = UIImageView(frame: CGRect(origin: .zero, size: CGSize(width: size.width * percentage, height: size.height * percentage)))
imageView.contentMode = .ScaleAspectFit
imageView.image = self
UIGraphicsBeginImageContextWithOptions(imageView.bounds.size, false, scale)
guard let context = UIGraphicsGetCurrentContext() else { return nil }
imageView.layer.renderInContext(context)
guard let result = UIGraphicsGetImageFromCurrentImageContext() else { return nil }
UIGraphicsEndImageContext()
return result
}
func resizeWithWidth(width: CGFloat) -> UIImage? {
let imageView = UIImageView(frame: CGRect(origin: .zero, size: CGSize(width: width, height: CGFloat(ceil(width/size.width * size.height)))))
imageView.contentMode = .ScaleAspectFit
imageView.image = self
UIGraphicsBeginImageContextWithOptions(imageView.bounds.size, false, scale)
guard let context = UIGraphicsGetCurrentContext() else { return nil }
imageView.layer.renderInContext(context)
guard let result = UIGraphicsGetImageFromCurrentImageContext() else { return nil }
UIGraphicsEndImageContext()
return result
}
이 그것을 사용하는 폭 크기를 조절하여 이러한 확장을 사용 작은 크기 먼저 이미지의 크기를 조정할 수 있습니다 16,
myImage = myImage.resizeWithWidth(700)!
지금 다음 당신은 여전히 당신의 선택의 압축 비율을 사용하여 압축 할 수
let compressData = UIImageJPEGRepresentation(myImage, 0.5) //max value is 1.0 and minimum is 0.0
let compressedImage = UIImage(data: compressData!)
당신은 이미지의 크기 (이하 크기 = 적은 데이터)를 변경하고 JPEG 등의 이미지 압축 알고리즘을 사용하여 압축 할 수 있습니다, 다른 방법 (더 좋은 algorythm = 같은 품질의 더 적은 크기)이 없습니다.
나는 구글이 최근 신경 네트워크를 사용하여 JPEG 알고리즘 (구글의 TensorFlow)
이 http://stackoverflow.com/a/38633826/1187415의 사본과 같은 개선 들었다. 그 전에 질문을하고 대답 한 것으로 생각된다면 그것을 중복으로 표시 할 수 있습니다. 기존 답변을 반복 할 필요가 없습니다. –