We are trying to implement the ability to display hexadecimal image data sent from the server side in Swift.
However, I don't know how to process the hexadecimal image data and display it as an image.
Now I can even receive image data from the server side at JSON.
func downloadBtn (sender: UIButton) {
// create url request
// set URL
let urlstr="http://192.168.33.10/test_app/images/recieveImage"
let request = NSMutableURLRequest (URL:NSURL (string:urlstr)!)
// set method
request.HTTPMethod="GET"
// Generate Task
let task = NSURLSession.sharedSession().dataTaskWithRequest(request, completionHandler: {data, response, error in
// succeeded post
if(error==nil){
let result = NSSstring (data:data!, encoding:NSUTF8StringEncoding)
// Output results
// Receive data from the server via JSON
let json = JSON (data:data!)
let resp = json ["resp"].string
print(resp)
/*
Verify the Output Is Hexadecimal Data
*/
//(1) Delete space
let deleteTarget=NSCCharacterSet.whitespaceCharacterSet
let img_data=resp!.stringByTrimmingCharactersInSet(deleteTarget())
// print("resp=\(img_data)")
} else {
print(error)
}
})
task.resume()
}
(1) removes the retrieved data because it has spaces at the beginning and end.
I think img_data
is String type, but I don't know how to handle it and display the image.
If anything happens, we will supplement it at any time.
Thank you for your cooperation.
This is an example of a 64-digit number, but I think it can be used as a reference.
http://blog.sarabande.jp/post/92097422168
887 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
567 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
577 PHP ssh2_scp_send fails to send files as intended
610 Uncaught (inpromise) Error on Electron: An object could not be cloned
© 2024 OneMinuteCode. All rights reserved.