我必須顯示像100 * 100像素的固定尺寸區域的圖像,但實際圖像尺寸太大(如400 * 450),問題是當我將大圖像設置爲100 * 100像素imageview然後滾動產生晃動的細胞Tableview cell when image size too too large
回答
我用這一行代碼來創建一個新的UIImage這是縮放。設置比例和方向參數來達到你想要的。第一行代碼只是抓住圖像。
// grab the original image
UIImage *originalImage = [UIImage imageNamed:@"myImage.png"];
// scaling set to 2.0 makes the image 1/2 the size.
UIImage *scaledImage =
[UIImage imageWithCGImage:[originalImage CGImage]
scale:(originalImage.scale * 2.0)
orientation:(originalImage.imageOrientation)];
最簡單的方法是設置的UIImageView的框架和contentMode設置的調整選項之一。
或者您可以使用此工具方法,如果你確實需要調整圖像大小:
+ (UIImage *)imageWithImage:(UIImage *)image scaledToSize:(CGSize)newSize {
//UIGraphicsBeginImageContext(newSize);
// In next line, pass 0.0 to use the current device's pixel scaling factor (and thus account for Retina resolution).
// Pass 1.0 to force exact pixel size.
UIGraphicsBeginImageContextWithOptions(newSize, NO, 0.0);
[image drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
謝謝...我用你的第一個解決方案及其在所有設備上的工作都很好(一些舊設備仍然存在混亂問題)。 –
但我有一個困惑是你的兩個解決方案是相同的或如果我用你的第二個答案。它會給出更好的解決方案。 PLZ建議我謝謝 –
第一個解決方案縮放圖像,但如果您需要使用第二個選項調整圖像大小 – oremag14jf
- 1. Hbase KeyValue size too large
- 2. Numpy array:sequence too large
- 3. Flask:session max size too
- 4. Mongorestore:ns name too too,max size is 128
- 5. TableView row too high
- 6. Flickr API iOS應用程序「POST size too large!」
- 7. python e **( - x)OverflowError:(34,'Result too large')
- 8. git push master not working files too too
- 9. While loop is too too far
- 10. vim「set wildmode = list:longest」issue when the too many matches
- 11. Array does not work read can not explain too too too explain
- 12. background-image:url()not working&image not too up
- 13. Android-Image Size change When get Focused
- 14. Jssor Images Too Zoomed
- 15. cvtColor too Slow
- 16. Jixed Bar Too Horozontally
- 17. Jasper Report Error:ORA-01555:snapshot too old:rollback segment number with name「」too small ORA-22924:snapshot too old
- 18. Tableview cell content is changed when cell off screen
- 19. python file read「int too large to convert to c long」
- 20. HTML5文件API:onload too slow
- 21. iTextSharp PDF table too much columns Issue
- 22. 爲什麼我從Perl中得到「Day too large」錯誤?
- 23. Mongodb異常,「MongoCursorException」消息'$ operator made object too large「是什麼意思?
- 24. Tableview cell change cell backgroung image(png)on點擊
- 25. Begin Storyboard too late(Silverlight)
- 26. Unity mobile scrollrect too sensitive
- 27. Python poplib error_proto:line too long
- 28. ng-style apply too late
- 29. Paraview glyphs too packed issues
- 30. ffmpeg - filter_complex list too long
其稱爲混蛋。並請顯示您的'cellForRow'方法代碼 – Shubhank