About Swift Image Processing

Asked 1 years ago, Updated 1 years ago, 89 views

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.

swift php json

2022-09-30 19:18

1 Answers

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


2022-09-30 19:18

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.