Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
  • How to convert NSData to UIImage in iOS

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 911
    Comment on it

    Hi Readers,

    This blog includes the concept of converting NSData to UIImage with the help of a very simple example. Given below is the screenshot and code which is used to convert NSData to UIImage on button click. Snapshot of storyboard is given below:-




    Code for the same is given below:-

    #import <UIKit/UIKit.h>
    @interface ViewController : UIViewController
    @property (weak, nonatomic) IBOutlet UIImageView *imgView;
    - (IBAction)btnConvert:(id)sender;
    #import "ViewController.h"
    #import "StringDeclaration.h"
    @interface ViewController ()
    @implementation ViewController
    - (void)viewDidLoad {
        [super viewDidLoad];
        // Do any additional setup after loading the view, typically from a nib.
    - (void)didReceiveMemoryWarning {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    - (IBAction)btnConvert:(id)sender {
        NSString *filePath = [[NSBundle mainBundle] pathForResource:@"Data" ofType:@"txt"];
        NSError *error;
        NSString *myText = [NSString stringWithContentsOfFile:filePath usedEncoding:nil error:&error];
        NSData *data = [[NSData alloc] initWithBase64EncodedString:myText options:NSDataBase64DecodingIgnoreUnknownCharacters]; //
        UIImage *convertImageFromNSData = [UIImage imageWithData:data];






    You can also download the project from the link given below:-

 0 Comment(s)

Sign In

Sign up using

Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: