2013-04-21 35 views
0

我有一個圖像,我正在使用自定義UITableViewCell。該圖像是透明背景上的黑色三角形,我使用CIColorInvert過濾器將其設置爲透明背景上的白色三角形。CIImage過濾器垂直拉伸我的圖像

過濾(倒置)圖像被垂直拉伸,我怎麼能阻止這種情況發生?

如果我直接加載UIImage沒有做什麼,我得到的過濾是這樣的:

arrow ok, but black

如果我申請了CIFilter我所得到的是這樣的:

enter image description here

這裏的我的代碼:

// create the white triangle 
CIImage *inputImage = [[CIImage alloc] initWithImage: 
         [UIImage imageNamed:@"TriangleRight"]]; 

CIFilter *invertFilter = [CIFilter filterWithName:@"CIColorInvert"]; 
[invertFilter setDefaults]; 
[invertFilter setValue: inputImage forKey: @"inputImage"]; 

CIImage *outputImage = [invertFilter valueForKey: @"outputImage"]; 

CIContext *context = [CIContext contextWithOptions:nil]; 

rightArrow = [UIImage imageWithCGImage:[context createCGImage:outputImage fromRect:outputImage.extent]]; 

在兩種情況下,我在UIImageView設置圖像如下:

cell.arrow.image = rightArrow; 

UIImageView尺寸是15×15(在IB)。 TriangleRight.png爲15x15像素,[email protected]爲30x30像素。

我錯過了什麼來防止CIFilter拉伸圖像?

更新:發佈我想通了這個問題的問題 5分鐘後:我使用的是自動佈局和UIImageView沒有一個明確的高度約束(僅寬度)。增加明確的高度約束解決了這個問題。但是,這仍然不能解釋爲什麼使用UIImage直接工作(即使沒有明確的高度限制)。

回答

1
UIImageOrientation originalOrientation = self->imageview.image.imageOrientation; 
imageview.image = [[UIImage alloc] initWithCGImage:imgRef scale:1.0  orientation:originalOrientation]; 

此外,使用原始的方向應該已經修復它。