在 iPad 中,如何从用户绘图视图/jpg 构建 MIME 附件,以便可以通过 SOAP Web 服务上传
我需要通过 SOAP Web 服务将 ipad 上的用户签名上传到服务器。签名将是 Web 服务的 MIME 附件。
需要帮助了解如何将 iOS 上的 UIView 或 jpg 转换为二进制数据 MIME 格式,以便我可以将其作为 Web 服务的一部分。另外,NSURLConnection
如何处理二进制数据附件。多谢。
I need to upload an user signature on ipad to server by SOAP web service. The signature will be a MIME attachment for the web service.
Need help to see how can the UIView
or jpg on iOS can be converted to binary data MIME format so I can put it as part of the web service. Also, how the NSURLConnection
can handle the binary data attachment. Thanks a lot.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果需要 JPEG 或 PNG 格式数据,可以使用 UIImageJPEGRepresentation 或 UIImagePNGRepresentation 将 UIImage 转换为 NSData 对象。如果您需要其他格式,您可以使用 CGImageDestination;可以从 CGImageDestinationCopyTypeIdentifiers。如果您只需要原始像素数据,请将图像绘制到 CGBitmapImageContext,然后使用 CGBitmapContextGetData; 如何获取像素来自 UIImage (Cocoa Touch) 或 CGImage (Core Graphics) 的数据? 可能会帮助你。
就 NSURLConnection 而言,帖子无论如何都是使用 NSData 完成的。您可以将 multipart/form-data 结构或 SOAP XML 文档正确格式化为 NSData,然后 NSURLConnection 可以很好地处理它。
If you need JPEG or PNG format data, you can use UIImageJPEGRepresentation or UIImagePNGRepresentation to convert a UIImage to an NSData object. If you need another format, you may be able to use CGImageDestination; a list of accepted UTIs can be obtained from CGImageDestinationCopyTypeIdentifiers. If you just need raw pixel data, draw the image to a CGBitmapImageContext and then read out the buffer using CGBitmapContextGetData; How to get pixel data from a UIImage (Cocoa Touch) or CGImage (Core Graphics)? may help you there.
As far as NSURLConnection, posts are done using an NSData anyway. It's up to you to format the multipart/form-data structure or SOAP XML document correctly into an NSData, but then NSURLConnection will handle it fine.
查看 Apple 的
GLPaint
示例代码,它将为您提供绘制签名的视图。它在我的测试中效果很好(尽管您需要更改画笔纹理图像): http://developer.apple.com/library/ios/#samplecode/GLPaint/Introduction/Intro.html然后,正如 Anomie 所说,你可以使用
CGBitmapContextGetData()
来访问绘制的图像,UIImage
可以为您将其转换为 JPEG。使用
NSURLRequest
或第三方 SOAP 库将 JPEG 发送到服务器。Check out the
GLPaint
sample code from Apple, which will give you a view for drawing the signature. It works well in my testing (although you'll want to change the brush texture image): http://developer.apple.com/library/ios/#samplecode/GLPaint/Introduction/Intro.htmlThen, as Anomie said, you can use
CGBitmapContextGetData()
to access the drawn image, andUIImage
can convert that into a JPEG for you.Use
NSURLRequest
or a third party SOAP library to send the JPEG to the server.