我需要实际的pixcel位置而不是相对于UIImageView框架的positoin,而是UIImage上的实际pixcel位置。
UIpangesture识别器在UIimageView中提供位置,因此没用。
我可以将x和y乘以比例,但UIImage比例始终为0.
我需要从UIImage裁剪一个圆形区域使其模糊并将其精确放置在同一位置
流速:
从UIimage中裁剪圆形区域:g CGImageCreateWithImageInRect
然后使用:[[UIBezierPath bezierPathWithRoundedRect:
使用CIGaussianBlur
将圆形矩形模糊图像放在x,y位置
在第一步中,我需要用户点击的实际像素位置
答案 0 :(得分:0)
这取决于图像视图内容模式。
对于缩放到填充模式,您需要简单地将坐标与图像相乘以查看比率:
CGPoint pointOnImage = CGPointMake(pointOfTouch.x*(imageSize.width/frameSize.width), pointOfTouch.y*(imageSize.height/frameSize.height));
对于所有其他模式,您需要计算视图中具有不同过程的实际图像帧。
从评论中添加宽高比适合模式:
对于宽高比拟合,您需要计算实际图像帧,该帧可以小于其中一个维度中的图像视图帧并放置在中心位置:
CGSize imageSize; // the original image size
CGSize imageViewSize; // the image view size
CGFloat imageRatio = imageSize.width/imageSize.height;
CGFloat viewRatio = imageViewSize.width/imageViewSize.height;
CGRect imageFrame = CGRectMake(.0f, .0f, imageViewSize.width, imageViewSize.height);
if(imageRatio > viewRatio) {
// image has room on top and bottom but fits perfectly on left and right
CGSize displayedImageSize = CGSizeMake(imageViewSize.width, imageViewSize.width / imageRatio);
imageFrame = CGRectMake(.0f, (imageViewSize.height-displayedImageSize.height)*.5f, displayedImageSize.width, displayedImageSize.height);
}
else if(imageRatio < viewRatio) {
// image has room on left and right but fits perfectly on top and bottom
CGSize displayedImageSize = CGSizeMake(imageViewSize.height * imageRatio, imageViewSize.height);
imageFrame = CGRectMake((imageViewSize.width-displayedImageSize.width)*.5f, .0f, displayedImageSize.width, displayedImageSize.height);
}
// transform the coordinate
CGPoint locationInImageView; // received from touch
CGPoint locationOnImage = CGPointMake(locationInImageView.x, locationInImageView.y); // copy the original point
locationOnImage = CGPointMake(locationOnImage.x - imageFrame.origin.x, locationOnImage.y - imageFrame.origin.y); // translate to fix the origin
locationOnImage = CGPointMake(locationOnImage.x/imageFrame.size.width, locationOnImage.y/imageFrame.size.height); // transform to relative coordinates
locationOnImage = CGPointMake(locationOnImage.x*imageSize.width, locationOnImage.y*imageSize.height); // scale to original image coordinates
如果您想要转换填充方面,只需注意,您需要在两个if语句中交换<
和>
。