假设我的图像是100x100 . 我想将图像放在更大的500x500的画布上 .
我目前的方法是使用UIGraphics创建一个Context,然后将图像绘制到上下文中 .
UIGraphics.BeginImageContext(....);
ImageView.Draw (....);
这很有效,但是我喜欢它,因为它正在做我正在做的事情 . 我注意到CIFilters非常快 . Is there a way I can place an image on a larger canvas size using CIFilters, or another method that uses the GPU and not the CPU?? 我've experimented with the CIFilters CICrop and CIPerspectiveTransform but I can'似乎得到了我想要的结果......
原始图像100x100
我想要的结果图像为500x500 . 我只是想使用CIFilters或一些GPU操作来拍摄图像并增加它的画布大小 .
我尝试使用CICrop进行“反向裁剪”,但这不起作用 . 注意我指定CIVector的大小为500x500,即使图像本身是100x100,结果图像完全忽略了额外的空间,如果关闭则切断 . 这是我的代码:
CICrop crop = new CICrop();
crop.Image = ImageView.Image.CGImage;
crop.Rectangle = new CIVector(0, 0, 500, 500);
ImageView.Image = new UIImage(crop.OutputImage);
Console.WriteLine("ImageView.Image.size = "+ ImageView.Image.Size);
1 回答
裁剪滤镜无法满足您的需要 - 您无法使用裁剪滤镜缩放输入图像的大小 . 来自维基百科:裁剪是指去除图像的外部部分以改善框架,突出主题或改变纵横比 .
你需要的是一个比例过滤器 . 要使用CoreImage实现此目的,您需要执行以下操作: