C#圖片壓縮EncoderParameter參數的坑,


EncoderParameter p;
EncoderParameters ps;

ps = new EncoderParameters(1);
p = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 100);
ps.Param[0] = p;
ImageCodecInfo myImageCodecInfo = GetCodecInfo("image/jpeg");
zipbmp.Save("d:\\111.jpg", myImageCodecInfo, ps);

在處理到圖片壓縮保存時,測試是圖片質量參數隨便輸入了100這么個數字,結果在參數初始化的時候就被識別成了byte類型,而造成.Save參數無效的錯誤(正確的應該要是long類型參數),而必須用下面的方式定義一個int類型,再調用才正常。

int Qty = 100;
p = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, Qty);

感覺有點坑,或許單輸入一個“100”,C#沒那么想當然就識別成整數

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM