简体   繁体   中英

create a UIImage from points

I have a UIWebView which has images in it, say that I have the point/coordinates of the xy position of the image, width and height. Can I create an image just by specifying the location of the image in UIWebView ? If yes how?

Or is there a way to get an UIImage from a UIWebView without actually looking at the <img src=""> of the html tags? Basically I don't want to make a connection to the internet to pull an image as the image is already there seen on the screen. Question is how do I extract it?

Depending on the cache policy in place, a request to retrieve the image may not result in another connection to download the image... But to answer your actual question...

You can take a 'snapshot' of the UIWebView and then crop to the location of the image in question. Check this question out for details on how to do this: How Do I Take a Screen Shot of a UIView?

This link explain a way to get the image just by grabbing it from the specified coordinates. How to create a UIImage from the current graphics context? .

However there might be a more elegant solution of using some javascript to get the original image by using the stringByEvaluatingJavaScriptFromString: method of UIWebview. But I am not sure if javascript is capable of doing it

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM