如何在ios中找到原始图像中的像素位置 [英] How to find the pixel location in original image in ios

查看:33
本文介绍了如何在ios中找到原始图像中的像素位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个尺寸为 480x360 的图像,并且在 UIImageview 中显示,框架为 (0, 0, 320, 568)>aspectfill.

I have an image with size 480x360 and am displaying in UIImageview with frame (0, 0, 320, 568) with aspectfill.

当我触摸图像视图时,位置显示 (150,120).如何以原始图像 (480x360) 格式映射此位置?

When I touch the image view, location says (150,120). How can I map this location in my original image (480x360) format?

谢谢

推荐答案

您只需计算比例并将其应用于触摸位置点.

You just calculate the proportions and apply them to touch location point.

CGFloat _x = imageView.image.size.width / imageView.frame.size.width;
CGFloat _y = imageView.image.size.height / imageView.frame.size.height;

//assuming p - is CGPoint received from Touch event
CGPoint locationInImageView = CGPointMake(p.x * _x, p.y * _y);

这篇关于如何在ios中找到原始图像中的像素位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆