ios4 - How to save .jpg image as .png or .jpeg in iphone -


i saving images in doc dir..i dont have problem .png or .jpeg images.i able display them in iphone.but coming .jpg,i not able display.please me in this.thanks in advance

+(void)downloadimage:(nsstring*)imagepath{  if ([imagepath isequaltostring:@""]) {     return; }  uiimage *dimage = [[uiimage alloc] initwithdata:[nsdata datawithcontentsofurl:[nsurl urlwithstring:[nsstring stringwithformat:@"http://1xyz/uploads/%@",imagepath]]]]; nsstring *docdir = [nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, yes) objectatindex:0]; nslog(@"pathimagepaths:::::::%@",imagepath); nslog(@"path:::::::%@",docdir); nsarray *patharr=[imagepath componentsseparatedbystring:@"."]; nsstring* ext=[nsstring stringwithformat: @"%@",[patharr objectatindex:1]]; nsstring *filepath = [nsstring stringwithformat: [nsstring stringwithformat:@"%@/%@",docdir,imagepath]]; nslog(@"%@/%@",docdir,imagepath); if([ext isequaltostring:@"png"]) {     nslog(@"saving png");     nsdata *data1 = [nsdata datawithdata:uiimagepngrepresentation(dimage)];     [data1 writetofile:filepath atomically:yes]; } else if([ext isequaltostring:@"jpeg"]) {     nslog(@"saving jpeg");     nsdata *data2 = [nsdata datawithdata:uiimagejpegrepresentation(dimage, 1.0f)];//1.0f = 100% quality     [data2 writetofile:filepath atomically:yes]; } else  {     nsdata *data3 = [nsdata datawithdata:uiimagejpegrepresentation(dimage, 1.0f)];     [data3 writetofile:filepath atomically:yes];  } nslog(@"saving image done");  [dimage release];  } 

you can use uiimagepngrepresentation. first create uiimage original jpg , them use class method save png.

uiimage *image = [uiimage imagenamed:@"yourimage.jpg"] nsdata *imagedata = uiimagepngrepresentation(image); 

once have data can save disk calling writetourl:.


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -