ios - 为什么要拉伸(stretch)图像(UIImage to CIImage to UIImage)
<p><p>由于某些原因,我需要将图像从 UIImage 转换为 CIImage(用于处理)并再次转换回 UIImage。我是通过UIImage-CGImage-CIImage-UIImage来做的。忽略不相关的代码,代码在后面显示。</p>
<pre><code>UIImage *originalPic = [init];//get this from UIImagePickerController
CIImage *originalCIPic = [init];
originalCIPic = ;
UIImage *finalResultUIImage = ;
//then I put the image on an Image View(contentMode has been set)
self.viewOfImage.contentMode = UIViewContentModeScaleAspectFit;
self.viewOfImage.image=finalResultUIImage;
//I used NSLog to check the size, but they are the same.(before transforming and after)
NSLog(@"this is the final UIImage,size is %@ ",NSStringFromCGSize(finalResultUIImage.size));
</code></pre>
<p>但是屏幕上显示的图像被拉伸(stretch)了。 </p>
<p>我怎么了?或者我还有其他选择吗?</p>
<p>非常感谢您,很抱歉我没有足够的声誉来发布图片。
:)</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p><strong>试试这个:</strong> </p>
<pre><code>NSString *filePath = [ pathForResource:@"abcd" ofType:@"png"];
CIImage *ciImage = ];
UIImage *imageByCIImage = ;
UIGraphicsBeginImageContext(imageByCIImage.size);
;
UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
self.imageview.image = newImage;
UIGraphicsEndImageContext();
</code></pre></p>
<p style="font-size: 20px;">关于ios - 为什么要拉伸(stretch)图像(UIImage to CIImage to UIImage),我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/29057398/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/29057398/
</a>
</p>
页:
[1]