2013-07-17 17 views
0

我有一個UIScrollView我在它以這種方式最好的初步實踐得出明確的圖像中的UIScrollView

- (UIImage *)pageControlImageWithIndex:(NSInteger)index{ 
NSString *imagePath = [NSHomeDirectory() stringByAppendingFormat:@"/Documents/t%d.jpg",index]; 
NSFileHandle *fileHandle = [NSFileHandle fileHandleForReadingAtPath:imagePath]; 
return [UIImage imageWithData:[fileHandle readDataToEndOfFile]]; 

}

UIImage *image = [self pageControlImageWithIndex:pageNumber]; 
UIGraphicsBeginImageContext(CGSizeMake(320.0, 164)); 
[image drawInRect:CGRectMake(0, 0, 320.0, 164.0)]; 
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); 
self.view.backgroundColor = [UIColor colorWithPatternImage:newImage]; 

顯示圖像,但圖像顯得有些模糊

enter image description here

雖然在其他視圖中以這種方式顯示相同的圖像(在側的UIImageView)

NSFileHandle *fileHandle = [NSFileHandle fileHandleForReadingAtPath:[NSHomeDirectory() stringByAppendingFormat:@"/Documents/t%d.jpg",topicNum]]; 
[topicPicImageView setImage:[UIImage imageWithData:[fileHandle readDataToEndOfFile]]]; 

產生這種質量

enter image description here

我怎樣才能在UIScrollView中的圖像質量相同?

  • 所述的圖像尺寸爲640×360
  • 兩個圖像容器尺寸是320×164

回答

2

UIGraphicsBeginImageContext將創建上下文以1.0刻度,或非視網膜。但是你很可能想要創建一個與設備規模相匹配的環境。使用新的UIGraphicsBeginImageContextWithOptions(CGSize size, BOOL opaque, CGFloat scale)函數。

替換

UIGraphicsBeginImageContext(CGSizeMake(320.0, 164)); 

UIGraphicsBeginImageContextWithOptions(CGSizeMake(320.0, 164), YES, 0.0); 

0.0作爲尺度參數的意思是 「使用的裝置主畫面規模」。如果您的圖片具有透明度,您希望使用NO作爲第二個參數。

+0

AmAzing真的,非常感謝 – OXXY