[問題] 縮小圖片解析度

看板MacDev作者 (創業維艱)時間11年前 (2013/12/12 00:21), 編輯推噓1(109)
留言10則, 3人參與, 最新討論串1/1
原po使用nsdata存取網路圖片,用uiimage呈現在tableview上. 經常因圖片太大,很容易記憶體不足當掉. 有沒有方法可以將nsdata裡的圖片縮小,降低bytes? -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 114.137.213.249

12/12 09:32, , 1F
UIGraphicsBeginImageContext(smallSize);
12/12 09:32, 1F

12/12 09:32, , 2F
[image drawInRect:imageRect];
12/12 09:32, 2F

12/12 09:33, , 3F
sImage = UIGraphicsGetImageFromCurrentImageContext();
12/12 09:33, 3F

12/12 09:33, , 4F
UIGraphicsEndImageContext();
12/12 09:33, 4F

12/12 09:34, , 5F
not the best way, but a simple way
12/12 09:34, 5F

12/12 12:48, , 6F
另一個問題 有沒有辦法可以偵測到圖太大的錯誤
12/12 12:48, 6F

12/12 12:48, , 7F
以避免程式會crash
12/12 12:48, 7F

12/12 16:42, , 8F
didReceiveRespose可以取得圖的大小
12/12 16:42, 8F

12/12 16:42, , 9F
[response expectedContentLength]
12/12 16:42, 9F

12/12 16:44, , 10F
可以在圖太大的話[connection cancel]
12/12 16:44, 10F
文章代碼(AID): #1Ig93-Tt (MacDev)
文章代碼(AID): #1Ig93-Tt (MacDev)