標籤:style color io 使用 ar for sp 資料 div
圖片壓縮:
NSData *imageData = UIImageJPEGRepresentation(self.uploadImage , 0.55);
NSString *file_name = [TimeUtil getDateStringWithFormat:@"yyyy-MM-dd"];
NSString *upload_name =[NSString stringWithFormat:@"%@.jpg",file_name ];
[request setData:imageData withFileName:upload_nameandContentType:@"image/jpeg" forKey:@"upload_file"];
UIImageJPEGRepresentation 函數須要兩個參數:圖片的引用和壓縮係數.
UIImagePNGRepresentation僅僅須要圖片引用作為參數.
比較發現:
UIImagePNGRepresentation(UIImage* image) 要比UIImageJPEGRepresentation(UIImage* image, 1.0) 返回的圖片資料量大非常多.
譬如,相同是讀取網路攝影機拍攝的相同景色的照片
UIImagePNGRepresentation()返回的資料量大小為199K
而 UIImageJPEGRepresentation(UIImage* image, 1.0)返回的資料量大小僅僅為140KB
比前者少了50多KB.
假設對圖片的清晰度要求不高,還能夠通過設定 UIImageJPEGRepresentation函數的第二個參數,大幅度減少圖片資料量.
譬如,剛才拍攝的圖片, 通過調用UIImageJPEGRepresentation(UIImage* image, 1.0)讀取資料時,返回的資料大小為140KB
但更改壓縮係數後,通過調用UIImageJPEGRepresentation(UIImage* image, 0.5)讀取資料時,返回的資料大小僅僅有11KB多,
大大壓縮了圖片的資料量
並且從視角角度看,圖片的品質並沒有明顯的減少.因此,在讀取圖片資料內容時,建議優先使用UIImageJPEGRepresentation
上傳圖片映像進行壓縮後上傳