ios - Convert NSData To UIImage -


first of selecting images in 1 listingstep1view , passing uiimages other view controller using sharedinstance.

listingstep1viewcontroller:

- (void)elcimagepickercontroller:(elcimagepickercontroller *)picker didfinishpickingmediawithinfo:(nsarray *)info {     [self dismissviewcontrolleranimated:yes completion:nil];       (uiview *v in [_scrollview subviews]) {         [v removefromsuperview];     }      nslog(@"info :%@", info);      cgrect workingframe = _scrollview.frame;     workingframe.origin.x = 0;      nsmutablearray *temparray =[[nsmutablearray alloc] init];      nsmutablearray *images = [nsmutablearray arraywithcapacity:[info count]];      (int =0; i<info.count; i++) {          nsdictionary *dict = [info objectatindex:i];          if ([dict objectforkey:uiimagepickercontrollermediatype] == alassettypephoto){              if ([dict objectforkey:uiimagepickercontrolleroriginalimage])             {                  uiimage* image = [dict objectforkey:uiimagepickercontrolleroriginalimage];                  [iphonexmppappdelegate load_uploadingimage:[image fixorientation]];                  nsdata* data = uiimagejpegrepresentation([iphonexmppappdelegate get_upload_image], 1.0f);                 //nsstring *encodedimage = [data base64encoding];                  [base64 initialize];                 self.convertedimage=[[uiimage alloc]initwithdata:data];           //self.convertedimage=[uiimage imagewithdata:data];         nslog(@"converted data image= %@",self.convertedimage);                nsstring *strencoded = [base64 encode:data];  strencoded = [strencoded stringbyreplacingoccurrencesofstring:@"+" withstring:@"%2b"];                [temparray addobject:strencoded];                  [images addobject:image];                  uiimageview *imageview = [[uiimageview alloc] initwithimage:image];                 [imageview setcontentmode:uiviewcontentmodescaleaspectfit];                 imageview.frame = workingframe;                 [_scrollview addsubview:imageview];                 workingframe.origin.x = workingframe.origin.x + workingframe.size.width;             } else {                 nslog(@"uiimagepickercontrollerreferenceurl = %@", dict);             }         }         else if ([dict objectforkey:uiimagepickercontrollermediatype] == alassettypevideo){              if ([dict objectforkey:uiimagepickercontrolleroriginalimage]){                 uiimage* image=[dict objectforkey:uiimagepickercontrolleroriginalimage];                  [images addobject:image];                  uiimageview *imageview = [[uiimageview alloc] initwithimage:image];                 [imageview setcontentmode:uiviewcontentmodescaleaspectfit];                 imageview.frame = workingframe;                  [_scrollview addsubview:imageview];                  workingframe.origin.x = workingframe.origin.x + workingframe.size.width;             } else {                 nslog(@"uiimagepickercontrollerreferenceurl = %@", dict);             }         } else {             nslog(@"uknown asset type");         }     }      self.chosenimages = images;        [[listingstep2model sharedinstance]setimagesassetarray:temparray];     //[[listingstep2model sharedinstance]setconvertedimage:self.convertedimage.image];      [_scrollview setpagingenabled:yes];     [_scrollview setcontentsize:cgsizemake(workingframe.origin.x, workingframe.size.height)];   } 

listingstep5viewcontoller:

for (int = 0; < [[[listingstep2model sharedinstance] imagesassetarray]count]; i++) {         nsmutablearray *images = [nsmutablearray arraywithcapacity:[[[listingstep2model sharedinstance] imagesassetarray]count]];                //uiimage*imagetodata=[[listingstep2model sharedinstance] convertedimage];       nslog(@"data imges:%@", [[[listingstep2model sharedinstance] imagesassetarray] objectatindex:i]);         //nslog(@"data imges:%@", imagetodata);          nsdictionary *dict;           if ([dict objectforkey:uiimagepickercontrollermediatype] == alassettypephoto){              if ([dict objectforkey:uiimagepickercontrolleroriginalimage])             {               {                     uiimage* image = [dict objectforkey:uiimagepickercontrolleroriginalimage];                      [iphonexmppappdelegate load_uploadingimage:[image fixorientation]];                      nsdata* data = uiimagejpegrepresentation([iphonexmppappdelegate get_upload_image], 1.0f);                                         //uiimageview *imgv = [[uiimageview alloc]init];                      [base64 initialize];                      nsstring *strencoded = [base64 encode:data];    strencoded = [strencoded stringbyreplacingoccurrencesofstring:@"+" withstring:@"%2b"];                      nsmutabledictionary *param = [nsmutabledictionary dictionary];                     [param setobject:strencoded forkey:[nsstring stringwithformat:@"image%d",i]];                }                  } else {                     nslog(@"uiimagepickercontrollerreferenceurl = %@", dict);                 }             }         }      [iphonexmppappdelegate startindicator];      nsmutablearray *totalrequest = [[nsmutablearray alloc] init];     [totalrequest addobject:param];      [requestandresponsehandlers helparucommonrequestandresponsehandlerwithparam:[nsdictionary dictionarywithobjectsandkeys:totalrequest,@"request",nil] methodname:methodname completionhandler:^(nsdictionary *response) {          nslog(@"response :%@", response);          if ([[response valueforkeypath:@"response.httpcode"] integervalue]==200) {           [[iphonexmppappdelegate appdelegate] navigateto:[iphonexmppappdelegate publicview ]];         }         else {             [iphonexmppappdelegate alertwithtitle:@"alert" message:@"please try again!"];         }          [iphonexmppappdelegate stopindicator];          [self.containertbl reloaddata];     }];  } 

output in nsdata format:

4qbyrxhpzgaatu0akgaaaagaagesaamaaaabaaeaaidpaaqaaaabaaaajgaaaaaaa6abaamaaaabaaeaakacaaqaaaabaaaeckadaaqaaaabaaac9gaaaad/7qa4ughvdg9zag9widmumaa4qklnbaqaaaaaaaa4qklnbcuaaaaaabduhyzzjwcybomaczjs%2bej%2b/8aaeqgc9grwaweraairaqmraf/eab8aaaefaqebaqebaaaaaaaaaaabagmebqyhcakkc//ealuqaaibawmcbamfbqqeaaabfqecawaeequsitfbbhnryqcicrqygzghccncscevuthwjdnicoijchyxgbkajsynkckqndu2nzg5okneruzhselku1rvvldywvpjzgvmz2hpann0dxz3ehl6g4sfhoeiiyqsk5svlpeymzqio6slpqeoqaqys7s1tre4ubrcw8tfxsfiycrs09tv1tfy2drh4upk5ebn6onq8flz9px29/j5%2bv/eab8baambaqebaqebaqeaaaaaaaabagmebqyhcakkc//ealuraaibagqeawqhbqqeaaecdwabagmrbauhmqysqvehyxetijkbcbrckagxwqkjm1lwfwjy0qowjdthjfexgbkajicokso1njc4otpdrevgr0hjslnuvvzxwflay2rlzmdoawpzdhv2d3h5eokdhiwgh4ijipktljwwl5iz 

first need change base64string nsdata , can convert uiimage. here steps:

(1) convert base64string nsdata using nsdata+base64 files.

nsdata *imagedata = [nsdata datafrombase64string:originalstring]; 

(2) can convert nsdata image follows:

uiimage *newimage = [uiimage imagewithdata:imagedata]; 

Comments

Popular posts from this blog

java - Could not locate OpenAL library -

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

sorting - opencl Bitonic sort with 64 bits keys -