我使用這個代碼在iPhone上調整圖像大小:調整UIImage的縱橫比?
CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0);
UIGraphicsBeginImageContext(screenRect.size);
[value drawInRect:screenRect blendMode:kCGBlendModePlusDarker alpha:1];
UIImage *tmpValue = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
這是偉大的工作,只要圖像的長寬比匹配,新調整後的圖像中。我想修改它以保持正確的高寬比,並在圖像不顯示的任何位置放置黑色背景。所以我仍然會得到一個320x480的圖像,但在頂部和底部或兩側都有黑色,這取決於原始圖像的大小。
有沒有一種簡單的方法來做到這一點,類似於我在做什麼?謝謝!
下面是保持縱橫比的文章: http://stackoverflow.com/questions/7645454/resize-uiimage-by-keeping-aspect-ratio-and-width – 2013-05-12 02:05:45