iphone - 将 UIWebView 中的图像放入 UIImageView 中

标签 iphone ios4

我在加载网站的应用程序后台隐藏了一个 UIWebView,我想将从其中加载的图像之一放置到可见的 UIImageView 中。因为我正在加载的图像是基于 PHP session 的验证码,所以我不能直接将图像从 URL 加载到 UIImageView 中,我必须获取加载到 UIWebView 中的特定实例。谁能给我一些关于如何解决这个问题的建议?我似乎不知道从哪里开始......

最佳答案

此片段在 WebView 上抓取一个 50x50 像素的正方形,其原点为 (50,50)。将位置调整到验证码的位置(如果您知道它始终位于同一位置)。

UIImage* theImage;
UIGraphicsBeginImageContext(CGSizeMake(50,50));
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextTranslateCTM(context, -50, -50 );
[[[self webView] layer] renderInContext:context];
theImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
// now do stuff with theImage

您可能会发现需要将此代码(或您的版本)放入 webView 委托(delegate)中的 webViewDidFinishLoad: 方法中。 Web View ,即使是基本的 Web View ,通常也需要很长时间才能呈现。如果你太早抓取图像,你将不会得到你想要的。

关于iphone - 将 UIWebView 中的图像放入 UIImageView 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4907480/

相关文章:

iphone - 乌龙、SIO2 还是适合 3D iPhone 游戏新手的商业游戏引擎?

iphone - UITableView 返回的单元格中保留了什么状态 :dequeueReusableCellWithIdentifier?

iphone - 对 iPhone 上收到的短信使用react

ios - 如何编辑 backBarButtonItem (UINavigationItem) 的背景颜色? iOS 4.3 问题

ios - 未知转义序列 '\x20'

c++ - 为什么很难找到 C++ 3d 游戏教程

iphone - 我可以在我的程序中使用 Siri 吗?

iphone - 如何将返回的 NSArray 添加到 NSArray

iphone - 如果 UIApplicationMain() 永远不会返回,那么自动释放池什么时候被释放?

iphone - 检测当前显示的 UIkeyboard 类型?