objective c - Converting image to NSData & back is nil -
when do
uiimage *photo = [uiimage imagenamed:@"sample_thumbnail.png"]; self.thumbnail.image = photo;
i see thumbnail, png
, fine. when convert nsdata & doing:
uiimage *photo = [uiimage imagenamed:@"sample_thumbnail.png"]; nsdata *data = uiimagepngrepresentation(photo); self.photodata = [[nsstring alloc] initwithdata:data encoding:nsutf8stringencoding]; self.thumbnail.image = [uiimage imagewithdata:[self.photodata datausingencoding:nsutf8stringencoding]];
self.photodata
nil.
why happening?
i think problem way create image nsdata instance. give try 1 instead:
uiimage *photo = [uiimage imagenamed:@"sample_thumbnail.png"]; nsdata *data = uiimagepngrepresentation(photo); uiimage *image = [uiimage imagewithdata:data];
__update__
below excerpt this post
- (nsstring *)imagetonsstring:(uiimage *)image { nsdata *imagedata = uiimagepngrepresentation(image); return [imagedata base64encodedstringwithoptions:nsdatabase64encoding64characterlinelength]; } - (uiimage *)stringtouiimage:(nsstring *)string { nsdata *data = [[nsdata alloc]initwithbase64encodedstring:string options:nsdatabase64decodingignoreunknowncharacters]; return [uiimage imagewithdata:data]; }
Comments
Post a Comment