4

iOS では、私の UIImageView は "Aspect Fit" ですが、"CISepiaTone" などのタイプの CIFilter を実行すると、元の画像の縦横比が失われます。画像は UIImageView のサイズ全体に引き伸ばされます。

アスペクト比を維持するにはどうすればよいですか?

4

1 に答える 1

4

imageWithCIImage でフィルター処理された画像を作成している場合、適切な縦横比が得られません。フィルター出力 CIImage から CGImageRef を作成し、CGImageRef から UIImage を作成してみてください。

例:

// assume you already have CIImage *outputImage and *inputImage declared

// convert to CGImage to maintain proper aspect ratio and dimensions
CIContext *context = [CIContext contextWithOptions:nil];
CGImageRef imageRef = [context createCGImage:outputImage fromRect:inputImage.extent];
UIImage *filteredImage = [UIImage imageWithCGImage:imageRef];
CGImageRelease(imageRef);

次に、filteredImage で imageView を設定してみてください。

于 2015-01-05T06:46:53.123 に答える