将uiview呈现给uiimage的问题(Problems with rendering uiview to uiimage)
所以我设置了一个UIImageView和一个Label,并将它们组合成一个UIView(如我这里显示的图片)
我做了以下操作将此视图呈现给UIImage,并分享它将带来UIActivityViewController。
@IBOutlet var viewBack: UIView! @IBOutlet var dismissButton: UIButton! @IBOutlet var shareButton: UIButton! @IBOutlet var imageView: UIImageView! @IBOutlet var hello: UILabel! var image = UIImage() override func viewDidLoad() { super.viewDidLoad() shareButton.backgroundColor = UIColor.grayColor() shareButton.setTitleColor(UIColor.whiteColor(), forState: .Normal) shareButton.layer.cornerRadius = 10 // Do any additional setup after loading the view. dismissButton.backgroundColor = UIColor.grayColor() dismissButton.layer.cornerRadius = 10 viewBack.backgroundColor = UIColor(white: 1, alpha: 0.0) UIGraphicsBeginImageContextWithOptions(viewBack.bounds.size, viewBack.opaque, 0.0) viewBack.drawViewHierarchyInRect(viewBack.bounds, afterScreenUpdates: false) imageView.drawViewHierarchyInRect(imageView.frame, afterScreenUpdates: false) hello.drawViewHierarchyInRect(hello.frame, afterScreenUpdates: false) let snapshotImageFromMyView = UIGraphicsGetImageFromCurrentImageContext() UIGraphicsEndImageContext() print(snapshotImageFromMyView) image = snapshotImageFromMyView } @IBAction func dismiss(sender: AnyObject) { dismissViewControllerAnimated(true, completion: nil) } @IBAction func share(sender: AnyObject) { var shareArray : [AnyObject] = [] shareArray.append(image) let activityVC = UIActivityViewController(activityItems: shareArray, applicationActivities: nil) if let popover = activityVC.popoverPresentationController{ popover.sourceView = sender as? UIView popover.sourceRect = sender.bounds } self.presentViewController(activityVC, animated: true, completion: nil) }
所以viewBack是UIView包含两个子视图--UIImage和标签。 而且似乎是我正常设置所有渲染过程。 但是当我真正分享它时,结果真的很奇怪,一张黑色照片。 显然我将图像视图设置为特定图像,标签也不是空的。 我不知道这里有什么问题,希望有人可以帮助我。 提前致谢。
So I set up an UIImageView and a Label, and put them together to a single UIView(as my picture shown here)
And I did the following to render this view to an UIImage, and share it which will bring the UIActivityViewController.
@IBOutlet var viewBack: UIView! @IBOutlet var dismissButton: UIButton! @IBOutlet var shareButton: UIButton! @IBOutlet var imageView: UIImageView! @IBOutlet var hello: UILabel! var image = UIImage() override func viewDidLoad() { super.viewDidLoad() shareButton.backgroundColor = UIColor.grayColor() shareButton.setTitleColor(UIColor.whiteColor(), forState: .Normal) shareButton.layer.cornerRadius = 10 // Do any additional setup after loading the view. dismissButton.backgroundColor = UIColor.grayColor() dismissButton.layer.cornerRadius = 10 viewBack.backgroundColor = UIColor(white: 1, alpha: 0.0) UIGraphicsBeginImageContextWithOptions(viewBack.bounds.size, viewBack.opaque, 0.0) viewBack.drawViewHierarchyInRect(viewBack.bounds, afterScreenUpdates: false) imageView.drawViewHierarchyInRect(imageView.frame, afterScreenUpdates: false) hello.drawViewHierarchyInRect(hello.frame, afterScreenUpdates: false) let snapshotImageFromMyView = UIGraphicsGetImageFromCurrentImageContext() UIGraphicsEndImageContext() print(snapshotImageFromMyView) image = snapshotImageFromMyView } @IBAction func dismiss(sender: AnyObject) { dismissViewControllerAnimated(true, completion: nil) } @IBAction func share(sender: AnyObject) { var shareArray : [AnyObject] = [] shareArray.append(image) let activityVC = UIActivityViewController(activityItems: shareArray, applicationActivities: nil) if let popover = activityVC.popoverPresentationController{ popover.sourceView = sender as? UIView popover.sourceRect = sender.bounds } self.presentViewController(activityVC, animated: true, completion: nil) }
So viewBack is the UIView contains two subviews- The UIImage and the label. And it seems to be that I set up all the rendering procedure normally. But when I actually share it, the result is really strange, a black picture. Apparently I set my image view to a specific image, and label isn't empty as well. I don't know what's wrong here, hopefully somebody could help me. Thanks in advance.
原文:https://stackoverflow.com/questions/39324333
最满意答案
这已经在stackoverflow上得到了回答:
IMO, the provider is telling you to change the service endpoint (i.e. where to reach the web service), not the client endpoint (I don't understand what this could be). To change the service endpoint, you basically have two options.
Use the Binding Provider to set the endpoint URL
The first option is to change the
BindingProvider.ENDPOINT_ADDRESS_PROPERTY
property value of theBindingProvider
(every proxy implementsjavax.xml.ws.BindingProvider
interface):... EchoService service = new EchoService(); Echo port = service.getEchoPort(); /* Set NEW Endpoint Location */ String endpointURL = "http://NEW_ENDPOINT_URL"; BindingProvider bp = (BindingProvider)port; bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpointURL); System.out.println("Server said: " + echo.echo(args[0])); ...
The drawback is that this only works when the original WSDL is still accessible. Not recommended.
Use the WSDL to get the endpoint URL
The second option is to get the endpoint URL from the WSDL.
... URL newEndpoint = new URL("NEW_ENDPOINT_URL"); QName qname = new QName("http://ws.mycompany.tld","EchoService"); EchoService service = new EchoService(newEndpoint, qname); Echo port = service.getEchoPort(); System.out.println("Server said: " + echo.echo(args[0])); ...
相关问答
更多-
IMO,提供商告诉您更改服务端点(即哪里到达Web服务),而不是客户端端点(我不明白这可能是什么)。 要更改服务端点,您基本上有两个选项。 使用绑定提供程序设置端点URL 第一个选项是更改BindingProvider.ENDPOINT_ADDRESS_PROPERTY属性值(每个代理实现javax.xml.ws.BindingProvider接口): ... EchoService service = new EchoService(); Echo port = service.getEchoPort() ...
-
通过JAX-WS WebService时截断的Java对象(Truncated Java object when passing through JAX-WS WebService)[2023-06-23]
如果您的Web服务将Agent元素定义为传入数据,那么就不可能将其解组为继承类。 我想有可能编写自己的编组,但它并不像听起来那么容易(我建议反对它)。 要么为每个类编写一个单独的WS(杂乱),要么使传入的数据具有可以存储其他结构的元素,例如type:any(也是凌乱的)。 事实是WS并不完全是OO。 If your webservice has Agent element defined as incoming data, then no it is not possible to unmarshall i ... -
我有很多错误需要解决。 我错过了要放在我使用Web服务的项目中的客户端jar文件,然后我需要使用WAS管理控制台指定JVM parameters 。 我把它放在了错误的地方。 -Djavax.net.ssl.trustStore=C:\IBM\RAD85\jdk\jre\lib\security\cacerts -Djavax.net.ssl.trustStorePassword=changeit I had a lot of errors to resolve. I was missing the c ...
-
由于底层HTTP协议,Web服务默认是无状态的。 服务器将每个Web服务请求处理为新的交互,即使它来自同一客户端 通常,JAX-WS Web服务是无状态的:也就是说,您在Web服务对象中设置的局部变量和对象值都不会从一次调用保存到下一次。 甚至来自单个客户端的顺序请求也被视为独立的无状态方法调用。 存在Web服务用例,其中客户端可能希望在一次调用期间在服务上保存数据,然后在后续调用期间使用该数据。 例如,可以通过重复调用addToCart Web方法添加购物车对象,然后通过getCart Web方法获取。 ...
-
这已经在stackoverflow上得到了回答: 如何更改webservice url端点? IMO, the provider is telling you to change the service endpoint (i.e. where to reach the web service), not the client endpoint (I don't understand what this could be). To change the service endpoint, you basic ...
-
JAX-WS服务部署(JAX-WS service deployment)[2022-02-20]
Oracle Java 文档声明如下 创建并发布给定地址的指定实现者对象的端点。 必要的服务器基础架构将由JAX-WS实现使用一些默认配置来创建和配置。 由于JAX-WS是Java SE软件包的一部分,这意味着底层服务器取决于您正在运行程序的JVM的类型。 例如,在我的笔记本电脑上,我正在运行一个Java 8 OpenJDK,其中创建了一个“com.sun.net.httpserver.HttpServer”实例。 查找您的环境中启动的服务器的最快方法,只需跳到Endoint.java(实施)的(反编译)代 ... -
使用PHP SoapClient和Java JAX-WS RI(Webservice)(Using PHP SoapClient with Java JAX-WS RI (Webservice))[2022-07-25]
如果超时,看起来php无法正确解析WSDL URL。 您是否在WSDL Url上尝试过file_get_contents()/ curl? 也许尝试调用IP而不是localhost,看看它是怎么回事。 If it times out it looks like php isn't able to resolve the WSDL URL properly. Have you tried a file_get_contents()/curl on the WSDL Url? Maybe try calling ... -
Web服务器 您称之为Web服务端点的只不过是在某个主机上侦听的Web服务器(通常为0.0.0.0)以及物理机或虚拟机上的某个端口,并对发送到该主机,端口和URI的HTTP请求进行响应。 Web服务器关心处理。 任何Web服务器本身都是应用程序或应用程序的静态或动态组件,如以下示例所示: JBoss,Glassfish,Tomcat等是应用程序,称为应用程序服务器,其中部署了实现Web服务器和相应端点的容器/ servlet /插件。 这些侦听某些端口,暴露通用Web服务器将请求路由到这些容器及其servl ...
-
我已经解决了在app.config中的绑定标记中添加httpTransport的问题:
-
连接超时试图从JAX-WS调用asmx https Web服务(Connection timed out trying to call asmx https web service from JAX-WS)[2023-01-23]
您是否尝试设置https代理而不是http代理? System.setProperty("https.proxyHost", "proxy ip"); System.setProperty("https.proxyPort", "port"); Did you try setting the https proxy, instead of http proxy? System.setProperty("https.proxyHost", "proxy ip"); System.setProperty("h ...