我想知道我的iPhone应用程序如何利用特定的屏幕截图UIView作为UIImage.
我试过这段代码,但我得到的只是一张空白图片.
UIGraphicsBeginImageContext(CGSizeMake(320,480));
CGContextRef context = UIGraphicsGetCurrentContext();
[myUIView.layer drawInContext:context];
UIImage *screenShot = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
Run Code Online (Sandbox Code Playgroud)
myUIView尺寸为320x480,并且有一些子视图.这样做的正确方法是什么?
嗨,我正在尝试将pdf文件另存为jpg文件。我有许多要查询的网址,这些网址链接都是1页pdf文件。
var path = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0] as! String
let urlRequest = NSURLRequest(URL: NSURL(string: downloadUrl[index])!)
NSURLConnection.sendAsynchronousRequest(urlRequest, queue: NSOperationQueue.mainQueue()) { (response, data, error) -> Void in
var savePath = path.stringByAppendingPathComponent(file_name + ".jpg")
if let httpResponse = response as? NSHTTPURLResponse {
if let contentType = httpResponse.allHeaderFields["Content-Type"] as? NSString {
let fileType = contentType.componentsSeparatedByString("/").last! as! String
if fileType == "pdf" {
// convert to jpg before saving!
NSFileManager.defaultManager().createFileAtPath(savePath, contents: convertedData, attributes: nil)
} else {
NSFileManager.defaultManager().createFileAtPath(savePath, contents: data, attributes: nil)
}
self.tableView.reloadData()
} …Run Code Online (Sandbox Code Playgroud)