2013-05-07 19 views
0

當我們在iphone上拍攝照片時,圖像以全屏顯示,頂部沒有任何「灰色條」,即圖像顯示在框中320 * 500尺寸。我想在我的應用程序中顯示該圖像,但該應用程序的最大幀大小爲320 * 480。因此,當我嘗試以全屏方式在我的應用中顯示圖像時,它會顯示爲拉伸圖像。我嘗試了所有contentMode選項,但沒有奏效。 那麼,如何縮放圖像或如何修復框架的大小,以便圖像以原樣顯示,但在較小的框架中沒有任何失真或類似於iPhone的「照片」應用程序?適當縮放UIImage使其全屏顯示而不會產生任何扭曲

回答

1

當您拍攝照片時,實際上看不到全尺寸的照片,您只會看到適合顯示屏的部分(照片的分辨率大於iPhone的顯示分辨率)。因此,如果您想拍攝最終圖像並將其全屏顯示,那麼您需要進行一些簡單的計算以縮放圖像,使其比例正確:

// We know the desired resolution. It's full screen (320, 480) or (640, 960). 
// Now we want to determine the destination imageView frame with maximum dimensions 
// for it to fit the screen AND leave the image's proportions 
float minScale = MIN(screenResolution.width/actualImgWidth, screenResolution.height/actualImgHeight); 
// With minScale one side will fit full screen, and the other will occupy a bit smaller space than the screen allows 
destImgView.bounds = CGRectMake(0, 0, minScale*actualImgWidth, minScale*actualImgHeight); 
destImgView.image = actualImg;