my NSData object contains within byte of a photo.
I would like to convert this object to a UIImage.
My problem is that he could not give a name all’oogetto UIImage. example myphoto.jpg
this is my code:
NSString * bytestring =(NSString *)[bean image];
//contain byte of my photo
NSData * byte = [bytestring dataUsingEncoding:NSUTF8StringEncoding];
UIImage *image=[[UIImage alloc]initWithData:byte];
UIButton *bt=[[UIButton alloc]initWithFrame:CGRectMake(80,80,100,100)];
[bt setImage:image forState:UIControlStateNormal];
[self.boxView addSubview:bt];
the button does not display my photos.
how can I do?
Since it appears that
[bean image]is actually a base 64 encoding of the image’s data, you need to use a method to convert the encoded data back into unencoded data.There is no standard method for this but there are plenty you can find and use. Your code then becomes something like this:
Have a look at:
convert base64 decoded NSData to NSString