上傳圖片映像進行壓縮後上傳

來源:互聯網
上載者:User

標籤: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


上傳圖片映像進行壓縮後上傳

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.