我正在尝试在webView中使用UIImagePickerController显示用户捕获的照片。我能想到的唯一逻辑解决方案是捕获文件路径并将其包含在HTML中。我已经实现了这个,但图像没有显示,我只是得到一个带有替代文字的白色框。
是否有解决方案让这个工作?
func imagePickerController(picker: UIImagePickerController, didFinishPickingImage image: UIImage!, editingInfo: [NSObject : AnyObject]!) {
if cameraBool {
let imageData = UIImageJPEGRepresentation(image, 0.6)
let compressedJPGImage = UIImage(data: imageData!)
ALAssetsLibrary().writeImageToSavedPhotosAlbum(compressedJPGImage!.CGImage, orientation: ALAssetOrientation(rawValue: compressedJPGImage!.imageOrientation.rawValue)!,
completionBlock:{ (path:NSURL!, error:NSError!) -> Void in
//capture file path as string
self.pathString = String(path)
//Insert path as HTML URL
self.texttemp = "hello <img src=\"\(self.pathString)\" alt=\"user photo\" height=\"500\" width=\"300\"/>"
//Load HTML into webView
self.myWebView.loadHTMLString(self.texttemp, baseURL: self.baseURL)
print(self.texttemp) //Prints hello <img src="assets-library://asset/asset.JPG?id=78A82D22-7115-4C9B-B31F-8C8A57123AE7&ext=JPG" alt="user photo" height="500" width="300"/>
})
}
self.dismissViewControllerAnimated(true, completion: nil);
}