Base64 decoding issue with image data-iphone

I have some problem for decoding image data from base 64 encoded string. I am using base64.h and base 64.m files downloaded from the following link

http://cdn.imthi.com/e6cef8/wp-content/uploads/2010/08/base64.zip

This is my code

[Base64 initialize];
NSData * data = [Base64 decode:imageString];
imgview.image=[UIImage imageWithData:data];

but, nothing displayed in the image view ,

I tested by decoding the base 64 string(taken from debugger console) with an online base 64 decoder,It gives correct image, I also tested by writing the data to a file like this

[data writeToFile:imagePath atomically:YES];

it gives a jpg file but i can't open that image file, it gives error message like

The file “test.jpg” could not be opened.

"It may be damaged or use a file format that Preview doesn’t recognize." What is the problem with my code Can anyone help me.....

Thank you

Answers


Try a different base 64 implementation, I use the one from colloquy open source project:

    #import "NSDataAdditions.h" 

    /* encoded string to image */
    NSString *imageString = @"";
    NSData * data = [NSData dataWithBase64EncodedString:imageString];
    UIImage *image1 = [UIImage imageWithData:data];

    /* image to encoded string, back to image */
    imageString = [UIImagePNGRepresentation(image) base64Encoding];
    data = [NSData dataWithBase64EncodedString:imageString];
    UIImage *image2 = [UIImage imageWithData:data];

Get NSAdditions files: NSAdditions.h + NSAdditions.m


Need Your Help

Recursively output a binary tree in ascending order

c++ recursion binary-tree

My current implementation of how to output my binary tree is getting me an error in g++, along the lines of

Composer ignores whitelist

php composer-php

I have the following require sections in my composer.json:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.